I'd like to make a thread that shows the complete process of making an icon pack for noobs. I call this a "root thread" because I'm not really explaining all the processes, but amassing all the data from other threads and posts and putting it here. Most of what I do write will be the errors that I have come across and how to fix it.
Firstly, I'd like to bring to your attention some useful tools/sites:
Icon Request Tool: Allows users to send you activity names, as well as the icons
Png2xml: Adds all of the png files in the same folder into a drawable.xml file and an icon_pack.xml file in alphabetical order
My dropbox folder, which contains all the stock icons I have downloaded (this may lag as there are thousands of images). You may use this, but I recommend you work with the request tool and go from there as it makes app filters easier.
A xml duplicate line removing site
Setting Up Your Project - Read me first
This is going to be a complete guide on how to set up your project with no errors. I will be using the1dynasty's template from April 2014, but the concept is the same for all projects. If you still have errors after doing all this, DO NOT continue until it is fixed.
1. Import your project - Make sure you are importing android code. It is also recommended that you copy the project into your workplace to stay organized
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Add support library - as you should see, your project has errors. Right click on it, go to android tools, then add support library. Accept the conditions and add it.
3. If required, add extra libraries - as of now, this template requires actionbarsherlock. Firstly, you'll need to download that and do the 2 steps above. When in the android menu, make sure you check "is library" so you can add it. I would also recommend that you change the target name of all projects to the latest android version (android 4.4.2 for now). Then press apply and okay. Now, with the current template, you can add actionbarsherlock. Another way to add libraries is to copy a .jar file into the libs folder, but we don't need to worry about that now. This should git rid of the errors.
4. Rename application package - this is when you change the project to your needs. Again, right click on the project, go to android tools, and then rename application package. Please remember the original package name (your.icons.name.here in my case). Then, change it to the one you want (com.pitchedapps.icons in my case). Accept all the refractor changes and press finish.
5. Refractoring - you can probably see that in the src folder, the source packages still have your.icons.name.here in them. They need to each be done manually. You can right click on them, then go to refractor, then name, or press shift + alt + r. Change the original package name (your.icons.name.here) to your new package name (com.pitchedapps.icons) for each source package with it. The "view" package will remain as "view". If you are feeling masterful, you could also refractor the main project folder (last screenshot in this section). I renamed mine as "Pitched Apps Icons"
6. Rename everything else - for every project, it is inevitable that the previous two methods will not cover everything. This is why you do a full file search for the original package name. You can get to this panel with "ctrl + h". Please note to search in files and not java, and to search in enclosing projects (make sure you are selecting a file within the project so that you aren't searching in a different one). You can also search in a workplace set and manually select the project. You will get results like so. Next, just change the package names to your new one. I recommend putting them in find/replace (ctrl + f) so you don't accidentally mistype it
If you have no errors, then congratulations! You can now move on in making your icon pack
Setting Up Your Project
First, off, you can decide whether you want a plain icon pack, a theme maker or a full on app with interface.
The1dynasty made a really good template which can be found here. (has interface and everything). He also has a complete tutorial on making the template on youtube. If you have questions, post in his google + page. XDA user Blaze has also modified the pack to contain alex's request tool. Thread is here
If, however, you are looking for something simpler, look at this thread for Apex themes here. To make this compatible with other launchers, add the following code to the manifest (right above </manifest>)
HTML:
<intent-filter>
<action android:name="org.adw.launcher.THEMES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="org.adw.launcher.icons.ACTION_PICK_ICON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.anddoes.launcher.THEME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.teslacoilsw.launcher.THEME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.fede.launcher.THEME_ICONPACK" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.tsf.shell.themes" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="ginlemon.smartlauncher.THEMES" />
<action android:name="ginlemon.smartlauncher.BUBBLESTYLE" />
<action android:name="ginlemon.smartlauncher.BUBBLEICONS" />
<action android:name="ginlemon.smartlauncher.CLOCKS" />
<action android:name="ginlemon.smartlauncher.CLOCKFONTS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="org.adw.launcher.THEMES" />
<action android:name="mobi.bbase.ahome.THEME" />
<action android:name="com.rogro.GDE.THEME.1" />
<action android:name="com.android.dxtop.launcher.THEME" />
<category android:name="com.fede.launcher.THEME_ICONPACK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="org.adw.launcher.icons.ACTION_PICK_ICON" />
<action android:name="mobi.bbase.ahome.THEME" />
<action android:name="com.rogro.GDE.THEME.1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="cdproductions.crazyicons.TWO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.daeva112.manager.MAIN" />
<category android:name="com.daeva112.manager.THEME" />
</intent-filter>
<intent-filter>
<action android:name="com.gau.go.launcherex.theme" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
You are now all set!
The Drawables
Obviously speaking, the important parts in an icon pack include the drawables, and these three files: drawable.xml, icon_pack.xml, appfilter.xml
Firstly, looking at the drawables, you will notice multiple folders. The one I'm going to focus on is drawable-xxhdpi, one of the folders you can put your icons in. The icon sizes go as follow
HTML:
mdpi 160dpi 48px * 48px
hdpi 240dpi 72px * 72px
xhdpi 320dpi 96px * 96px
xxhdpi 480dpi 144px * 144px
xxxhdpi 640dpi 192px * 192px
You do not need to make icons for every size, as it will automatically be resized to fit devices. However, if you want hd apps, try to look at at least xxhdpi
Here is a link to my dropbox, where I keep all the stock icons (xxxhdpi). This (and the xml's) take the longest time to do, so it's just my way of giving back and thanking those that helped me. More info on xml's in the section below
Drawable Errors
If you are making all the drawables yourself, just know that there can be no capital letters (or ".") in your file name. If you have that, you will get many errors and eclipse won't generate a r.java file for you.
There is however an easy fix for those using windows. Simply go to the folder containing your images, hold shift, right click, and press run command window here. Then paste this code (ctrl v won't work, right click and press paste)
HTML:
for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")
Xml files
Drawable.xml - this is a list of all the icons in your app. It allows users to manually select the icon they want for a certain app through the launcher. As the launcher will display the icons in the same order as drawable.xml, this is best done alphabetically
Iconpack.xml - also written as icon_pack.xml in some templates - this tells the icon pack which drawables (icons) are currently available
The good thing about the two xml's above is that they are very easy to make. Simply put this java application in the folder with all the icons and run it, and it will make the files. Do this every time you make new icons! Again, make sure that your template uses iconpack.xml and not icon_pack.xml (like the apex template). To solve this, either rename your xml each time or search the project for icon_pack and change it to iconpack
Appfilter.xml - this one contains all the activities, and is what allows the app to automatically associated each app with its corresponding icons. Unfortunately, this must be done manually (or with the help of a tool). As mentioned in the beginning, here is a tool I made (source thanks to Alex R3conn3r to help you with this. It'll make an appfilter for you, so use it as reference.
As you can see, both appfilter and drawable are located in the assets and xml folders, and iconpack is in the values folder. Simply put, replace all your old xml's with your new ones in all three folders so that you support all the launchers. (To add more detail, xml is for most standard launchers, ie apex, nova etc), and assets is for go. Furthermore, if you use an icon request tool that filters out prethemed icons, it needs to look at an appfilter in assets)
Getting help from your users
***Easiest way is to implement alex's icon request tool. ***
This is mainly for the appfilter file. Finding the activities can be a very treacherous task, especially when there are many activities for each app. Two good manual sources are
http://activities.droidicon.com/
http://activities.tundem.com/
But you can also rely on apps like QuickShortcutMaker
An even more automatic alternative is Icon Helper, which I will write a guide on once I figure out how to use it
There is now a template that has an icon helper built into it (thread is here). Credits go to the1dynasty for his template, alex for his icon request tool, tung for the idea (he made icon helper), and blaze for doing the impossible and putting it all together
How to search in a whole project
Select the appropriate project (select any file in that project) and press ctrl + H. Then, do the following (underlined in blue)
In the example, I searched for "your.icons.name.here", which is the original package name for the1dynasty's pack. What I would recommend is that you search for the original package name and rename it to your pack, then search for ".com" to find the emails, and also whatever link or specific keyword you need to change
Editing strings
Most of the strings will be in the values folder (strings, strings_app, strings_dev, etc). It is just up to you to look through all of them. Some may also be hidden in java, so be sure to look there too! (try searching)
Info for the1dynasty's template
* FAQ - Read me first if you are new
Before doing anything, you must download actionbarsherlock (may be removed in future), and add support libraries to the project by right clicking and going to android tools --> add support library
To change the activity name (default is your.icons.name.here), you must:
Rename the application package - right click the project, go to android tools, and press rename package name (ie to com.asdfasdfvful.icons).
Rename the src package folders - (shortcut is alt + shift + R) - change all the "your.icons.name.here" to match your package name (so your.icons.name.here.util becomes com.asdfasdfvful.icons.util)
Do the ctrl + h thing as mentioned above (scroll up to blue title)
Drawables CANNOT start with numbers or contain special characters. Add the a letter (ie "a" to retain the order) and change the characters so eclipse does not explode
Drawable and app filter need to be in xml to support launchers like Nova, and assets for the request tool and the launchers like go. Icon_pack.xml should be in the values folder. Furthermore, if your icons are not theming, check the app drawer first. Often times, if you manually set an icon for an app, it will not change automatically after further updates (to change that, readd the app to your screen from the app drawer)
* Where is...? And a bunch of other small facts
How to I remove the title from the action bar?
Go to src, the Activity package folder, and then MainActivity.java. Or you can search for "setDisplayShowTitleEnabled". Change that to false. As for setDisplayShowHomeEnabled, that is for the icon.
How do I change the actionbar color?
Go to res/xhdpi/ab_transparent.9.png and modify that to your liking. You may also want to change the white50 in res/values/colors.xml
How do I change between listview and gridview?
Go to res/layout/gridview_behind (or search for "android:numColumns". Change the number (1 for list, 2, 3, whatever for gridview)
* Adding and removing cards
Go into src/fragments/mainfragment.java, and you will see two parts, both of which for phones and tablets
You will see something like
HTML:
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_app),
getResources().getString (R.string.desc_app), 0));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_request),
getResources().getString (R.string.desc_request), 1));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_production),
getResources().getString (R.string.desc_production), 2));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_apply),
getResources().getString (R.string.desc_apply), 3));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_walls),
getResources().getString (R.string.desc_walls), 4));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_xda),
getResources().getString (R.string.desc_xda), 5));
This is what tells the app what to show for each card. To change the name, icon, or description of any card, simply refer it to a different string or change the original string. To add a new card, just copy one of them, and paste it. Change the two R.string and the number before the "));"
The next part will look something like this
HTML:
switch (position) {
case 0:
Intent pitchedplay = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://play.google.com/store/apps/developer?id=Pitched+Apps"));
startActivity(pitchedplay);
break;
case 1:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.pitchedapps.icons.raging.shadows","com.pitchedapps.icons.raging.shadows.RequestActivity"));
startActivity(intent);
break;
case 2:
Intent production = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://goo.gl/OoIxqC"));
startActivity(production);
break;
case 3:
Intent launcher = new Intent(getSherlockActivity(), LauncherMain.class);
startActivity(launcher);
break;
case 4
Intent wall = new Intent(getSherlockActivity(), Wallpaper.class);
startActivity(wall);
break;
case 5:
Intent xda = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://forum.xda-developers.com/showthread.php?t=2669405"));
startActivity(xda);
break;
This gives each card its own function. You can reorder them as you like, but make sure the case number matches the first code. To add another function for a card, copy a case, change the number, the intent name, the start activity name (same as intent name) and the function.
* Adding removing buttons in the overflow menu
Go to activity/mainactivity.java or search for
HTML:
public boolean onOptionsItemSelected(MenuItem item)
Remove, rearrange, or add buttons as you please. Keep in mind that adding requires that you add the appropriate id's, so it's not for absolute beginners.
* Removing the oss pop up
Search for the following
HTML:
This code checks if MY OSS is installed on first run.
To see which files contain the code. Then remove everything up to the "}" before "@ Override" as shown:
HTML:
/******************************************************************************
** This code checks if MY OSS is installed on first run. If it is installed **
** you get a dialog that says you're awesome and the user hits OK to remove **
** that dialog. If it is NOT installed, the user is prompted to install it. **
** You can remove this section if you're not checking for apps on first run **
******************************************************************************/
public void onStart() {
super.onStart();
boolean installed = isAppInstalled("app.the1dynasty.oss");
// Checking if installed and if its the first run
if (installed) {
boolean firstrunOSS = getSharedPreferences("PREFERENCE", MODE_PRIVATE)
.getBoolean("firstrunOSS", true);
if (firstrunOSS){
/*
* Installed dialog
* Check res/values/strings.xml to change text to whatever you want the Alert to say
*/
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getResources().getString (R.string.alert_start_title));
alert.setMessage(getResources().getString (R.string.alert_start_desc));
alert.setIcon(R.drawable.alert_pass);
alert.setPositiveButton(getResources().getString (R.string.ok), null).show ();
// Save the state so this dialog doesn't run again
getSharedPreferences("PREFERENCE", MODE_PRIVATE)
.edit()
.putBoolean("firstrunOSS", false) /* You can change this to another name */
.commit();
}
}
/*
* Not Installed dialog
* Check res/values/strings.xml to change text to whatever you want the Alert to say
*/
else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString (R.string.error_start_title));
builder.setMessage(getResources().getString (R.string.error_start_desc));
builder.setIcon(R.drawable.alert_fail);
builder.setNeutralButton(getResources().getString (R.string.later), new OnClickListener(){
[user=439709]@override[/user]
public void onClick(DialogInterface arg0, int arg1) {
}
});
// Change line 88 with the URL to YOUR app
builder.setPositiveButton(getResources().getString (R.string.get), new OnClickListener(){
[user=439709]@override[/user]
public void onClick(DialogInterface arg0, int arg1) {
Intent share = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("market://details?id=app.the1dynasty.oss"));
startActivity(share);
}
});
builder.show();
}
}
* Adding wallpapers
Go to drawable_nodpi and add your wallpaper in the same format (wall_# & wall_#_small with dimensions 215x179)
Go to res/values/array.xml and add more lines for wallpapers (or just copy paste this) Note that you can add more than you actually have
HTML:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string-array name="wallpaperlist">
<item>wall_1</item>
<item>wall_2</item>
<item>wall_3</item>
<item>wall_4</item>
<item>wall_5</item>
<item>wall_6</item>
<item>wall_7</item>
<item>wall_8</item>
<item>wall_9</item>
</string-array>
<!-- Provide a list of wallpaers -->
<string-array name="wallpapers" translatable="true">
<item>wall_1</item>
<item>wall_2</item>
<item>wall_3</item>
<item>wall_4</item>
<item>wall_5</item>
<item>wall_6</item>
<item>wall_7</item>
<item>wall_8</item>
<item>wall_9</item>
</string-array>
<string-array name="extra_wallpapers">
</string-array>
<!-- This wallpaper will be used when a user applies the theme -->
<string name="default_wallpaper">wall_1</string>
<string-array name="dock_pack" translatable="false">
<item>dock_0002</item>
<item>dock_0003</item>
<item>dock_0004</item>
</string-array>
</resources>
You can also search the project for "wall_", and you will come across some other files. Some of them allow you to select the default wallpaper, so just change the # to the one you want.
Check out my icon pack!
Thank you for this helpful and very informative guide.:good:
cool, thank for doing this
Sent from my SCH-I535 using Tapatalk 2
Thanks ...
This post was really useful for beghinners like me
Nice
Sent from my GT-P3100 using XDA Premium 4 mobile app
hi thanks for sharing this link to me and for create this guide, howevere i ve one problem, i ve add 12 tabs and have modified main fragment.xml and main adapter.xml, i ve add the string for tabs into strings_app.xml but show up only 7 tabs ..... i foget to modify other files ?
fraom said:
hi thanks for sharing this link to me and for create this guide, howevere i ve one problem, i ve add 12 tabs and have modified main fragment.xml and main adapter.xml, i ve add the string for tabs into strings_app.xml but show up only 7 tabs ..... i foget to modify other files ?
Click to expand...
Click to collapse
Is this for the cards or the tabs in the menu? Of its cards, Make sure you edited both parts in main fragments. One for the function and one for actually showing the card. If it's menu, I believe there is another thing you need in an XML. Copy paste one the id of one of the tabs and search for it. Then you'll get the xml
Sent from my One S using Tapatalk
asdfasdfvful said:
Is this for the cards or the tabs in the menu? Of its cards, Make sure you edited both parts in main fragments. One for the function and one for actually showing the card. If it's menu, I believe there is another thing you need in an XML. Copy paste one the id of one of the tabs and search for it. Then you'll get the xml
Sent from my One S using Tapatalk
Click to expand...
Click to collapse
is for the card
this is my code for MainFragment.java
-----------------------------------------------
package your.icons.name.here.fragment;
import java.util.ArrayList;
import java.util.List;
import view.ScrollGridView;
import your.icons.name.here.R;
import your.icons.name.here.activity.AboutThemeActivity;
import your.icons.name.here.activity.AllIcons;
import your.icons.name.here.activity.ApplyLauncherMain;
import your.icons.name.here.activity.MainActivity;
import your.icons.name.here.activity.RequestActivity;
import your.icons.name.here.activity.Wallpaper;
import your.icons.name.here.adapter.MainAdapter;
import your.icons.name.here.adapter.MainAdapter.AdapterItem;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import com.actionbarsherlock.app.SherlockFragment;
/**
** Some lines may be off a few numbers
** Just be sure you're in the general area
**/
public class MainFragment extends SherlockFragment{
ScrollGridView gridView;
final List<AdapterItem> listOfStuff = new ArrayList<AdapterItem>();
public static final int APPLY = 0;
public static final int WALLPAPER = 1;
public static final int ALLICONS = 2;
public static final int SCREEN = 3;
public static final int REQUEST = 4;
public static final int PLAY = 5;
public static final int DEVG = 6;
public static final int GCOMMUNITY = 7;
public static final int TWITTER = 8;
public static final int FACEBOOK = 9;
public static final int WEB = 10;
public static final int CONTACT = 11;
// This is the background layout that gets inflated behind the list view
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.gridview_behind, null);
}
// Starts when the MainFragment is launched
@override
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
/*
* This part does two things
* First - It counts the number of items and displays them
* Second - It displays the text in the "" which is a brief description of that item
* Removing any of these will remove that item but be sure to edit ALL the cases below or your list
* won't line up properly
*/
/**
** NOTE: in order to have different views on tablet vs phones, I added an if/else statement to this
** section. Be sure to remove BOTH parts to remove it from phones and tablets. Failure to remove both
** parts will result in the app functioning differently on phones and tablets.
**/
/*
* Sets the Title and description text for each GridView item
* Check res/values/strings.xml to change text to whatever you want each GridView to say
*/
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
gridView = (ScrollGridView)getView().findViewById(R.id.grid);
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_apply),
getResources().getString (R.string.desc_apply), 0));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_walls),
getResources().getString (R.string.desc_walls), 1));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_icons),
getResources().getString (R.string.desc_icons), 2));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_screen),
getResources().getString (R.string.desc_screen), 3));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_request),
getResources().getString (R.string.desc_request), 4));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_play),
getResources().getString (R.string.desc_play), 5));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_dev),
getResources().getString (R.string.desc_dev), 6));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_community),
getResources().getString (R.string.desc_community), 7));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_twitter),
getResources().getString (R.string.desc_twitter), 8));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_fb),
getResources().getString (R.string.desc_fb), 9));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_web),
getResources().getString (R.string.desc_web), 10));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_contact),
getResources().getString (R.string.desc_contact), 11));
} else {
gridView = (ScrollGridView)getView().findViewById(R.id.grid);
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_apply),
getResources().getString (R.string.desc_apply), 0));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_walls),
getResources().getString (R.string.desc_walls), 1));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_icons),
getResources().getString (R.string.desc_icons), 2));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_screen),
getResources().getString (R.string.desc_screen), 3));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_request),
getResources().getString (R.string.desc_request), 4));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_play),
getResources().getString (R.string.desc_play), 5));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_dev),
getResources().getString (R.string.desc_dev), 6));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_community),
getResources().getString (R.string.desc_community), 7));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_twitter),
getResources().getString (R.string.desc_twitter), 8));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_fb),
getResources().getString (R.string.desc_fb), 9));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_web),
getResources().getString (R.string.desc_web), 10));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_contact),
getResources().getString (R.string.desc_contact), 11));
}
/**
** NOTE: in order to have different views on tablet vs phones, I added an if/else statement to this
** section. Be sure to remove both parts to remove it from phones and tablets. Failure to remove both
** parts will result in the app functioning differently on phones and tablets.
**/
MainAdapter adapter = new MainAdapter(getActivity(), listOfStuff);
gridView.setAdapter(adapter);
gridView.setExpanded(true);
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
@SuppressWarnings("unused")
MainFragment gridContentT = null;
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) { // For TABLETS
switch (position) {
case APPLY:
Intent launcher = new Intent(getSherlockActivity(), ApplyLauncherMain.class);
startActivity(launcher);
break;
case WALLPAPER:
Intent wall = new Intent(getSherlockActivity(), Wallpaper.class);
startActivity(wall);
break;
case ALLICONS:
Intent allIcons = new Intent(getSherlockActivity(), AllIcons.class);
startActivity(allIcons);
break;
case REQUEST:
Intent request = new Intent(getSherlockActivity(), RequestActivity.class);
startActivity(request);
break;
case SCREEN:
Intent aboutTheme = new Intent(getSherlockActivity(), AboutThemeActivity.class);
startActivity(aboutTheme);
break;
case DEVG:
Intent dev = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/+DevFraom"));
startActivity(dev);
break;
case GCOMMUNITY:
Intent community = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/communities/114921114033302801523"));
startActivity(community);
break;
case TWITTER:
Intent twitter = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://twitter.com/Fraom"));
startActivity(twitter);
break;
case FACEBOOK:
Intent fb = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://www.facebook.com/devFraom"));
startActivity(fb);
break;
case WEB:
Intent web = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://zeptorius.altervista.org"));
startActivity(web);
break;
case CONTACT:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{getResources().getString(R.string.email_address)});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
getResources().getText(R.string.email_subject));
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Contact Developer"));
break;
}
} else { // For PHONES
switch (position) {
case APPLY:
Intent launcher = new Intent(getSherlockActivity(), ApplyLauncherMain.class);
startActivity(launcher);
break;
case WALLPAPER:
Intent wall = new Intent(getSherlockActivity(), Wallpaper.class);
startActivity(wall);
break;
case ALLICONS:
Intent allIcons = new Intent(getSherlockActivity(), AllIcons.class);
startActivity(allIcons);
break;
case REQUEST:
Intent request = new Intent(getSherlockActivity(), RequestActivity.class);
startActivity(request);
break;
case SCREEN:
Intent aboutTheme = new Intent(getSherlockActivity(), AboutThemeActivity.class);
startActivity(aboutTheme);
break;
case DEVG:
Intent dev = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/+DevFraom"));
startActivity(dev);
break;
case GCOMMUNITY:
Intent community = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/communities/114921114033302801523"));
startActivity(community);
break;
case TWITTER:
Intent twitter = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://twitter.com/Fraom"));
startActivity(twitter);
break;
case FACEBOOK:
Intent fb = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://www.facebook.com/devFraom"));
startActivity(fb);
break;
case WEB:
Intent web = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://zeptorius.altervista.org"));
startActivity(web);
break;
case CONTACT:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{getResources().getString(R.string.email_address)});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
getResources().getText(R.string.email_subject));
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Contact Developer"));
break;
}
}
}
});
}
}
----------------------------
and this is the MainAdapter.java
package your.icons.name.here.adapter;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import your.icons.name.here.R;
public class MainAdapter extends BaseAdapter{
public static final int APPLY = 0;
public static final int WALLPAPER = 1;
public static final int ALLICONS = 2;
public static final int SCREEN = 3;
public static final int REQUEST = 4;
public static final int PLAY = 5;
public static final int DEVG = 6;
public static final int GCOMMUNITY = 7;
public static final int TWITTER = 8;
public static final int FACEBOOK = 9;
public static final int WEB = 10;
public static final int CONTACT = 11;
private Context context;
private List<AdapterItem> gridItem;
public MainAdapter(Context context, List<AdapterItem> gridItem) {
this.gridItem = gridItem;
this.context = context;
}
public View getView(int position, View v, ViewGroup parent) {
ViewHolder holder;
AdapterItem entry = gridItem.get(position);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.gridview_layout, null);
holder = new ViewHolder();
holder.title = (TextView) v.findViewById(R.id.title);
holder.text = (TextView) v.findViewById(R.id.description);
holder.icon_Image = (ImageView) v.findViewById(R.id.list_image);
v.setTag(holder);
}
else {
holder = (ViewHolder) v.getTag();
}
holder.title.setText(entry.getTitle());
/*
* Sets the font type for the title and description of each item
* This is if you want to have a bolder font for title or something
* Make sure the font file is in the projects Asset folder
* Default for this template is Roboto-Thin
* themefont.ttf is the font the theme grabs also
*/
Typeface tfTitle = Typeface.createFromAsset(context.getAssets(),"themefont.ttf");
Typeface tfDescription = Typeface.createFromAsset(context.getAssets(),"themefont.ttf");
holder.title.setTypeface(tfTitle);
holder.text.setTypeface(tfDescription);
/*
* Sets the description and title text color as well as icon shown
* You can reference any color in the colors.xml and even add some
* You can also individually set the color for each GridView by
* referencing a different color on each case statement (kinda like the different icon references)
* You can reference any drawable
*/
switch(entry.getID()){
case APPLY:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_launcher);
break;
case WALLPAPER:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_wall);
break;
case ALLICONS:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case SCREEN:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_info);
break;
case REQUEST:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_request);
break;
case PLAY:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case DEVG:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_gplus);
break;
case GCOMMUNITY:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_community);
break;
case TWITTER:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_twitter);
break;
case FACEBOOK:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case WEB:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case CONTACT:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_email);
break;
}
holder.text.setText(entry.getDescription());
holder.title.setText(entry.getTitle());
return v;
}
@override
public int getCount() {
return gridItem.size();
}
@override
public Object getItem(int position) {
return gridItem.get(position);
}
@override
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView title;
public TextView text;
public ImageView icon_Image;
}
public static class AdapterItem{
String Title;
String Description;
int ID;
public AdapterItem(String Title, String Description, int ID) {
this.Title = Title;
this.Description = Description;
this.ID = ID;
}
public String getTitle() {
return Title;
}
public String getDescription() {
return Description;
}
public int getID() {
return ID;
}
}
}
-----------------
the cards show about the number 6 , others ( community, twitter, Facebook, web e contact ) doesn't appears!
i ve attached the file, can you see it ?
fraom said:
is for the card
this is my code for MainFragment.java
HTML:
-----------------------------------------------
package your.icons.name.here.fragment;
import java.util.ArrayList;
import java.util.List;
import view.ScrollGridView;
import your.icons.name.here.R;
import your.icons.name.here.activity.AboutThemeActivity;
import your.icons.name.here.activity.AllIcons;
import your.icons.name.here.activity.ApplyLauncherMain;
import your.icons.name.here.activity.MainActivity;
import your.icons.name.here.activity.RequestActivity;
import your.icons.name.here.activity.Wallpaper;
import your.icons.name.here.adapter.MainAdapter;
import your.icons.name.here.adapter.MainAdapter.AdapterItem;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import com.actionbarsherlock.app.SherlockFragment;
/**
** Some lines may be off a few numbers
** Just be sure you're in the general area
**/
public class MainFragment extends SherlockFragment{
ScrollGridView gridView;
final List<AdapterItem> listOfStuff = new ArrayList<AdapterItem>();
public static final int APPLY = 0;
public static final int WALLPAPER = 1;
public static final int ALLICONS = 2;
public static final int SCREEN = 3;
public static final int REQUEST = 4;
public static final int PLAY = 5;
public static final int DEVG = 6;
public static final int GCOMMUNITY = 7;
public static final int TWITTER = 8;
public static final int FACEBOOK = 9;
public static final int WEB = 10;
public static final int CONTACT = 11;
// This is the background layout that gets inflated behind the list view
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.gridview_behind, null);
}
// Starts when the MainFragment is launched
[user=439709]@override[/user]
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
/*
* This part does two things
* First - It counts the number of items and displays them
* Second - It displays the text in the "" which is a brief description of that item
* Removing any of these will remove that item but be sure to edit ALL the cases below or your list
* won't line up properly
*/
/**
** NOTE: in order to have different views on tablet vs phones, I added an if/else statement to this
** section. Be sure to remove BOTH parts to remove it from phones and tablets. Failure to remove both
** parts will result in the app functioning differently on phones and tablets.
**/
/*
* Sets the Title and description text for each GridView item
* Check res/values/strings.xml to change text to whatever you want each GridView to say
*/
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
gridView = (ScrollGridView)getView().findViewById(R.id.grid);
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_apply),
getResources().getString (R.string.desc_apply), 0));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_walls),
getResources().getString (R.string.desc_walls), 1));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_icons),
getResources().getString (R.string.desc_icons), 2));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_screen),
getResources().getString (R.string.desc_screen), 3));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_request),
getResources().getString (R.string.desc_request), 4));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_play),
getResources().getString (R.string.desc_play), 5));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_dev),
getResources().getString (R.string.desc_dev), 6));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_community),
getResources().getString (R.string.desc_community), 7));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_twitter),
getResources().getString (R.string.desc_twitter), 8));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_fb),
getResources().getString (R.string.desc_fb), 9));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_web),
getResources().getString (R.string.desc_web), 10));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_contact),
getResources().getString (R.string.desc_contact), 11));
} else {
gridView = (ScrollGridView)getView().findViewById(R.id.grid);
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_apply),
getResources().getString (R.string.desc_apply), 0));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_walls),
getResources().getString (R.string.desc_walls), 1));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_icons),
getResources().getString (R.string.desc_icons), 2));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_screen),
getResources().getString (R.string.desc_screen), 3));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_request),
getResources().getString (R.string.desc_request), 4));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_play),
getResources().getString (R.string.desc_play), 5));
listOfStuff.add(new AdapterItem(getResources().getString (R.string.title_dev),
getResources().getString (R.string.desc_dev), 6));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_community),
getResources().getString (R.string.desc_community), 7));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_twitter),
getResources().getString (R.string.desc_twitter), 8));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_fb),
getResources().getString (R.string.desc_fb), 9));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_web),
getResources().getString (R.string.desc_web), 10));
listOfStuff.remove(new AdapterItem(getResources().getString (R.string.title_contact),
getResources().getString (R.string.desc_contact), 11));
}
/**
** NOTE: in order to have different views on tablet vs phones, I added an if/else statement to this
** section. Be sure to remove both parts to remove it from phones and tablets. Failure to remove both
** parts will result in the app functioning differently on phones and tablets.
**/
MainAdapter adapter = new MainAdapter(getActivity(), listOfStuff);
gridView.setAdapter(adapter);
gridView.setExpanded(true);
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
[user=5448622]@Suppress[/user]Warnings("unused")
MainFragment gridContentT = null;
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) { // For TABLETS
switch (position) {
case APPLY:
Intent launcher = new Intent(getSherlockActivity(), ApplyLauncherMain.class);
startActivity(launcher);
break;
case WALLPAPER:
Intent wall = new Intent(getSherlockActivity(), Wallpaper.class);
startActivity(wall);
break;
case ALLICONS:
Intent allIcons = new Intent(getSherlockActivity(), AllIcons.class);
startActivity(allIcons);
break;
case REQUEST:
Intent request = new Intent(getSherlockActivity(), RequestActivity.class);
startActivity(request);
break;
case SCREEN:
Intent aboutTheme = new Intent(getSherlockActivity(), AboutThemeActivity.class);
startActivity(aboutTheme);
break;
case DEVG:
Intent dev = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/+DevFraom"));
startActivity(dev);
break;
case GCOMMUNITY:
Intent community = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/communities/114921114033302801523"));
startActivity(community);
break;
case TWITTER:
Intent twitter = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://twitter.com/Fraom"));
startActivity(twitter);
break;
case FACEBOOK:
Intent fb = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://www.facebook.com/devFraom"));
startActivity(fb);
break;
case WEB:
Intent web = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://zeptorius.altervista.org"));
startActivity(web);
break;
case CONTACT:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{getResources().getString(R.string.email_address)});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
getResources().getText(R.string.email_subject));
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Contact Developer"));
break;
}
} else { // For PHONES
switch (position) {
case APPLY:
Intent launcher = new Intent(getSherlockActivity(), ApplyLauncherMain.class);
startActivity(launcher);
break;
case WALLPAPER:
Intent wall = new Intent(getSherlockActivity(), Wallpaper.class);
startActivity(wall);
break;
case ALLICONS:
Intent allIcons = new Intent(getSherlockActivity(), AllIcons.class);
startActivity(allIcons);
break;
case REQUEST:
Intent request = new Intent(getSherlockActivity(), RequestActivity.class);
startActivity(request);
break;
case SCREEN:
Intent aboutTheme = new Intent(getSherlockActivity(), AboutThemeActivity.class);
startActivity(aboutTheme);
break;
case DEVG:
Intent dev = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/+DevFraom"));
startActivity(dev);
break;
case GCOMMUNITY:
Intent community = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://plus.google.com/communities/114921114033302801523"));
startActivity(community);
break;
case TWITTER:
Intent twitter = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://twitter.com/Fraom"));
startActivity(twitter);
break;
case FACEBOOK:
Intent fb = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("https://www.facebook.com/devFraom"));
startActivity(fb);
break;
case WEB:
Intent web = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://zeptorius.altervista.org"));
startActivity(web);
break;
case CONTACT:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{getResources().getString(R.string.email_address)});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
getResources().getText(R.string.email_subject));
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Contact Developer"));
break;
}
}
}
});
}
}
----------------------------
and this is the MainAdapter.java
package your.icons.name.here.adapter;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import your.icons.name.here.R;
public class MainAdapter extends BaseAdapter{
public static final int APPLY = 0;
public static final int WALLPAPER = 1;
public static final int ALLICONS = 2;
public static final int SCREEN = 3;
public static final int REQUEST = 4;
public static final int PLAY = 5;
public static final int DEVG = 6;
public static final int GCOMMUNITY = 7;
public static final int TWITTER = 8;
public static final int FACEBOOK = 9;
public static final int WEB = 10;
public static final int CONTACT = 11;
private Context context;
private List<AdapterItem> gridItem;
public MainAdapter(Context context, List<AdapterItem> gridItem) {
this.gridItem = gridItem;
this.context = context;
}
public View getView(int position, View v, ViewGroup parent) {
ViewHolder holder;
AdapterItem entry = gridItem.get(position);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.gridview_layout, null);
holder = new ViewHolder();
holder.title = (TextView) v.findViewById(R.id.title);
holder.text = (TextView) v.findViewById(R.id.description);
holder.icon_Image = (ImageView) v.findViewById(R.id.list_image);
v.setTag(holder);
}
else {
holder = (ViewHolder) v.getTag();
}
holder.title.setText(entry.getTitle());
/*
* Sets the font type for the title and description of each item
* This is if you want to have a bolder font for title or something
* Make sure the font file is in the projects Asset folder
* Default for this template is Roboto-Thin
* themefont.ttf is the font the theme grabs also
*/
Typeface tfTitle = Typeface.createFromAsset(context.getAssets(),"themefont.ttf");
Typeface tfDescription = Typeface.createFromAsset(context.getAssets(),"themefont.ttf");
holder.title.setTypeface(tfTitle);
holder.text.setTypeface(tfDescription);
/*
* Sets the description and title text color as well as icon shown
* You can reference any color in the colors.xml and even add some
* You can also individually set the color for each GridView by
* referencing a different color on each case statement (kinda like the different icon references)
* You can reference any drawable
*/
switch(entry.getID()){
case APPLY:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_launcher);
break;
case WALLPAPER:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_wall);
break;
case ALLICONS:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case SCREEN:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_info);
break;
case REQUEST:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_request);
break;
case PLAY:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case DEVG:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_gplus);
break;
case GCOMMUNITY:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_community);
break;
case TWITTER:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_twitter);
break;
case FACEBOOK:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case WEB:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_oss);
break;
case CONTACT:
holder.title.setTextColor(context.getResources().getColor(R.color.list_title_color));
holder.text.setTextColor(context.getResources().getColor(R.color.list_desc_color));
holder.icon_Image.setImageResource(R.drawable.icon_email);
break;
}
holder.text.setText(entry.getDescription());
holder.title.setText(entry.getTitle());
return v;
}
[user=439709]@override[/user]
public int getCount() {
return gridItem.size();
}
[user=439709]@override[/user]
public Object getItem(int position) {
return gridItem.get(position);
}
[user=439709]@override[/user]
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView title;
public TextView text;
public ImageView icon_Image;
}
public static class AdapterItem{
String Title;
String Description;
int ID;
public AdapterItem(String Title, String Description, int ID) {
this.Title = Title;
this.Description = Description;
this.ID = ID;
}
public String getTitle() {
return Title;
}
public String getDescription() {
return Description;
}
public int getID() {
return ID;
}
}
}
-----------------
the cards show about the number 6 , others ( community, twitter, Facebook, web e contact ) doesn't appears!
i ve attached the file, can you see it ?
Click to expand...
Click to collapse
hm.... everything looks right and I don't believe you need to modify another file. If you tap each of the cards,do they function as they should? Maybe search for "gcommunity" or one of the original card names to see if there's another file. I'll look back into it once I go on my own eclipse
asdfasdfvful said:
hm.... everything looks right and I don't believe you need to modify another file. If you tap each of the cards,do they function as they should? Maybe search for "gcommunity" or one of the original card names to see if there's another file. I'll look back into it once I go on my own eclipse
Click to expand...
Click to collapse
yes all works, howevere now i test with other name.....
another question, when i tap on launcher card ( for apply the theme ) the list of launcher is small, how i can set it at full screen ?
@fraom
Checked again and I still don't see an error. Maybe try changing all the case names into numbers. So in the begging when you had
PHP:
public static final int APPLY = 0;
public static final int WALLPAPER = 1;
public static final int ALLICONS = 2;
public static final int SCREEN = 3;
public static final int REQUEST = 4;
public static final int PLAY = 5;
public static final int DEVG = 6;
public static final int GCOMMUNITY = 7;
public static final int TWITTER = 8;
public static final int FACEBOOK = 9;
public static final int WEB = 10;
public static final int CONTACT = 11;
Use the corresponding numbers instead of the names. Do that for both java files
Also press ctrl+shift+O to add any missing imports
asdfasdfvful said:
@fraom
Checked again and I still don't see an error. Maybe try changing all the case names into numbers. So in the begging when you had
PHP:
public static final int APPLY = 0;
public static final int WALLPAPER = 1;
public static final int ALLICONS = 2;
public static final int SCREEN = 3;
public static final int REQUEST = 4;
public static final int PLAY = 5;
public static final int DEVG = 6;
public static final int GCOMMUNITY = 7;
public static final int TWITTER = 8;
public static final int FACEBOOK = 9;
public static final int WEB = 10;
public static final int CONTACT = 11;
Use the corresponding numbers instead of the names. Do that for both java files
Also press ctrl+shift+O to add any missing imports
Click to expand...
Click to collapse
I solved it! I rewrote all the code with different names and now it works....
although I have not figured out what the problem was ......
fraom said:
I solved it! I rewrote all the code with different names and now it works....
although I have not figured out what the problem was ......
Click to expand...
Click to collapse
Lol éclipse is weird
Sent from my One S using Tapatalk
Andorid Studio?
Cool guide, thanks!
Can you make the same steps for Andorid Studio too?
paolorotolo said:
Cool guide, thanks!
Can you make the same steps for Andorid Studio too?
Click to expand...
Click to collapse
Sorry, but I don't have Android studio nor do I know how to use it. I'm not even sure if this project is compatible but if it is most steps should be the same
Sent from my One S using Tapatalk
asdfasdfvful said:
Sorry, but I don't have Android studio nor do I know how to use it. I'm not even sure if this project is compatible but if it is most steps should be the same
Click to expand...
Click to collapse
OK, thanks anyway. I tried all day to run it with Android Studio. I imported Sherlock but I still have a lot of errors, even with base (untouched) template.
paolorotolo said:
OK, thanks anyway. I tried all day to run it with Android Studio. I imported Sherlock but I still have a lot of errors, even with base (untouched) template.
Click to expand...
Click to collapse
I presume they do thing differently. Download eclipse and try it ☺
Sent from my One S using Tapatalk
When the Request Icons button is pressed
The app lists all the apps that are in the device
But except for gmail, google settings (as far as my phone is concerned)
Also when i want to submit the app details in a mail. Gmail is not listed in the corresponding pop up to select the app to start the mail process.
Any suggestions?
Am using the default picker tool in 1dynasty's app
akhi24nick said:
When the Request Icons button is pressed
The app lists all the apps that are in the device
But except for gmail, google settings (as far as my phone is concerned)
Also when i want to submit the app details in a mail. Gmail is not listed in the corresponding pop up to select the app to start the mail process.
Any suggestions?
Am using the default picker tool in 1dynasty's app
Click to expand...
Click to collapse
Hm. Try opening Gmail first and then filing the request. As for the google apps not showing, I'm not sure about that. Try the one I made with Alex's code (link in op) and see if that one works. For the one in the1dynasty's template, you'll have to ask Pkmmte as he made the code
Sent from my One S using Tapatalk
akhi24nick said:
When the Request Icons button is pressed
The app lists all the apps that are in the device
But except for gmail, google settings (as far as my phone is concerned)
Also when i want to submit the app details in a mail. Gmail is not listed in the corresponding pop up to select the app to start the mail process.
Any suggestions?
Am using the default picker tool in 1dynasty's app
Click to expand...
Click to collapse
Are you running an aosp or cm rom? If so, perhaps there's an issue with your gapps?
Related
Hello, I am new to java and having difficulties trying to set a restriction on one of my editText.
I am trying to develop an app that allows user to fill there information in the application and then send through an email client.
So for my phone number section i am trying to make a restriction for only 11 characters to be entered, also for all the fields to be completed to process through the next stage.
here is my coding:
package com.example.rumel.booking2;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
EditText personName, numberGuests, phoneNumber, date, time;
String name, guests, number, dte, tme;
Button sendEmail;
@override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializerVars();
sendEmail.setOnClickListener(this);
}
private void initializerVars() {
personName = (EditText) findViewById(R.id.etName);
numberGuests = (EditText) findViewById(R.id.etGuest);
phoneNumber = (EditText) findViewById(R.id.etPhone);
date = (EditText) findViewById(R.id.etDate);
time = (EditText) findViewById(R.id.etTime);
sendEmail = (Button) findViewById(R.id.button);
}
public void onClick (View v) {
// TODO Auto-generated method stub
convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
String[] to = new String[]{"[email protected]"};
String message = "Name: "
+ name
+ "\n"
+ " Number of Guests: "
+ guests
+ "\n"
+ " Contact Number: "
+ number
+ "\n"
+ " Date: "
+ dte
+ ", Time: "
+ tme
+ "\n"
+ "\n"
+ "Thank you";
Intent emailIntent = new Intent (Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Reservation");
emailIntent.putExtra(Intent.EXTRA_TEXT, message);
emailIntent.setType("message/rfc822");//rfc822 email protocol
startActivity(Intent.createChooser(emailIntent,"Email"));
}
private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() {
// TODO Auto-generated method stub
name = personName.getText().toString();
guests = numberGuests.getText().toString();
number = phoneNumber.getText().toString();
dte = date.getText().toString();
tme = time.getText().toString();
}
@override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
@override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Would appreciate any help, thank you
Hi y'all. I have recently been trying to make a calculator app in AS. However, the app stops when I click the calculate button. I also wanted to have it notify the user the result contained in the result variable, but the setContentText doesn't want to work. Code:
Code:
package firstapp.stars.com.firstapp;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddScrn extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
final Button button4;
button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView textView4 = (TextView) findViewById(R.id.textView4);
EditText editText7 = (EditText) findViewById(R.id.editText7);
EditText editText8 = (EditText) findViewById(R.id.editText8);
String mynum1=editText7.getText().toString();
String mynum2=editText8.getText().toString();
int result = Integer.parseInt(mynum1) + Integer.parseInt(mynum2);
textView4.setText(Integer.toString(result));
textView4.setText(result);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Calculator - Calculation result:")
String content = String.valueOf(result);
.setContentText(content);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_add_scrn, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Help.
Whats-a-username? said:
Hi y'all. I have recently been trying to make a calculator app in AS. However, the app stops when I click the calculate button. I also wanted to have it notify the user the result contained in the result variable, but the setContentText doesn't want to work. Code:
Code:
package firstapp.stars.com.firstapp;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddScrn extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
final Button button4;
button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView textView4 = (TextView) findViewById(R.id.textView4);
EditText editText7 = (EditText) findViewById(R.id.editText7);
EditText editText8 = (EditText) findViewById(R.id.editText8);
String mynum1=editText7.getText().toString();
String mynum2=editText8.getText().toString();
int result = Integer.parseInt(mynum1) + Integer.parseInt(mynum2);
textView4.setText(Integer.toString(result));
textView4.setText(result);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Calculator - Calculation result:")
String content = String.valueOf(result);
.setContentText(content);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_add_scrn, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Help.
Click to expand...
Click to collapse
Regarding the following code:
textView4.setText(Integer.toString(result));
textView4.setText(result);
Why you assign the value twice?
The first assignment is OK, but the second one need to removed.
The result variable is an Integer type, and when you assign Integer to TextView, it will look for a sting resource id (in the strings xml).
If the id is not found, it can throw an exception.
Yes, but the app still crashes when the button is clicked and still doesn't want to notify me.
Still Active Errors
1. In the setContentTitle it says" ; expected", but when ; is placed, it highlights everything.
2. "Cannot resolve method setContentText".
Whats-a-username? said:
1. In the setContentTitle it says" ; expected", but when ; is placed, it highlights everything.
2. "Cannot resolve method setContentText".
Click to expand...
Click to collapse
Your code is incorrect.
Change you code to the following:
String content = String.valueOf(result);
Notification notification = new Notification.Builder(this)
.setContentTitle("Calculator - Calculation result:")
.setContentText(content).build();
Hi all,
Some days ago I decided to make an app to help me in my job with some Maths, so I'm reading a lot and watching some classes on youtube to make it possible. I'm trying to make, basically, a calculator for some specific maths.
By a simple way, I learned how to make my EditText,TextView , and do the Math when I push one BUTTON, but in some cases, for a fast and easy result, would be better to update the "children" field, just when I edit the "parent" field, or when I leave it.
Like, if I type the number 1 in my first field, the second field that depends on it should update automatically using this reference that I just edited.
Is there possible ? If yes, recommended or it makes the app too "heavy" ? Considering that each activity would have just few maths, far from any big known app.
Thanks in advanced.
Barata
Hello,
Let's suppose you have one EditText and one TextView, with ids in your xml: myedittext1 and mytextview2. You can easily achieve that. I don't think that it will be heavy just for few maths But also if it is heavy, it can be done without making the UI thread unresponsive, using thread for the calculations.
So
Code:
final EditText et1 = (EditText) findViewById(R.id.myedittext1);
final TextView tv2 = (TextView) findViewById(R.id.mytextview2);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
//This is called AFTER the text has changed
//Now update the tv2
String textOutput = ...;
//tv2.setText(textOutput);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//This is called BEFORE the text has changed
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//This is called WHENEVER the text has changed
}
});
Button b1 = (Button) findViewById(R.id.mybutton);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//do your math calculations here (if they are heavy, start a thread here)
//Edit the et1 here
//tv2 will be edited automatically according to the afterTextChanged above
}
});
If you would like to start a thread (if your maths are heavy), to avoid UI pausing and slow response from UI, follow the below code
//Thread solution (avoid making UI "laggy")
Before onCreate inside you Activity class:
Code:
EditText et1 = null;
TextView tv2 = null;
Thread t1 = null;
MyCalc mycalc = null;
MyCalc2 mycalc2 = null;
private class MyCalc implements Runnable{
public MyCalc(){
}
@Override
public void run(){
//Do you math here
final String outputText = ...;
try{
runOnUiThread(new Runnable() {
@Override
public void run() {
//Here set et1 text
et1.setText(outputText);
//tv2 text will be updated automatically
}
});
}catch (InterruptedException e){
}
});
}
private class MyCalc2 implements Runnable{
public MyCalc2(){
}
@Override
public void run(){
//Do you math here
final String outputText = ...;
try{
runOnUiThread(new Runnable() {
@Override
public void run() {
//Here set et1 text
et1.setText(outputText);
//tv2 text will be updated automatically
}
});
}catch (InterruptedException e){
}
});
}
Inside onCreate:
Code:
et1 = (EditText) findViewById(R.id.myedittext1);
tv2 = (TextView) findViewById(R.id.mytextview2);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
//This is called AFTER the text has changed
//if you need to do calculation here also, do:
mycalc2 = new MyCalc2(); //where MyCalc2 is the same as MyCalc but with different calculations :P
t1 = new Thread(mycalc2);
t1.start();
//Set tv2 text here.
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//This is called BEFORE the text has changed
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//This is called WHENEVER the text has changed
}
});
Button b1 = (Button) findViewById(R.id.mybutton);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
mycalc = new MyCalc();
t1 = new Thread(mycalc);
t1.start();
}
});
In onDestroy:
Code:
if(t1!=null){
if(t1.isAlive()==true){
if(t1.isInterrupted()==false){
t1.interrupt();
try{
t1.join();
}catch (InterruptedException e){
}
}
}
t1= null;
}
If you still need help, feel free to ask
Really thanks for the reply @MMDeveloper, but had some problems here, I'm trying to find a Solution for almost 1hr, and nothing.. I saw some ppeople with the same problem, but couldnt use the answers I've read to solve this code.
With the first solution you gave to me, I just delete the button part, just to try make all automatic. In this first sample I have just a simple math that should convert a CV power do kW
The studio shows that to me:
addTextChangedListener - Cannot resolve symbol;
TextWatcher - Invalid method declaration, return type required;
@Override - Annotations are not allowed here;
Editable arg0 - Cannot resolve symbols, for both;
I tried to put this code in different places in my main java, but nothing. Below is my XML and then my Java, could you take a look in it please ? I guess I'm used to copy and paste some codes from some classes, and that is harming me, i really need to start all over from the java sintaxe.
The fields I've changed to be those in your code are: torque_p_cv (edit) and torque_p_cv (view)
XML:
Code:
<RelativeLayout xmlns:android="CANT SHOW LINK UNDER 10 POSTS"
xmlns:tools="CANT SHOW LINK UNDER 10 POSTS"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Calculos001_Main">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cálc. do torque em função de P e n"
android:id="@+id/torque_titulo"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold|italic" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="P"
android:id="@+id/torque_tits_p" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Potência do motor"
android:id="@+id/textView"
android:layout_marginStart="10dp" />
<EditText
android:layout_width = "0dp"
android:layout_height="wrap_content"
android:id="@+id/torque_p_cv"
android:layout_weight="1"
android:inputType="number"
android:hint="Potência"
android:gravity="end"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="CV"
android:id="@+id/unidade_CV"
android:textAlignment="textEnd"
android:gravity="end"
android:layout_marginStart="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="xxxxx"
android:id="@+id/torque_p_kw"
android:textAlignment="textEnd"
android:gravity="end"
android:layout_marginStart="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="kW"
android:id="@+id/unidade_kW"
android:textAlignment="textEnd"
android:gravity="end"
android:layout_marginStart="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
and the Java:
Code:
package com.example.tbarata.calculos_001;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
public class Calculos001_Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculos001__main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_calculos001__main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
final EditText et1 = (EditText) findViewById(R.id.torque_p_cv);
final TextView tv2 = (TextView) findViewById(R.id.torque_p_kw);
et1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
//This is called AFTER the text has changed
//Now update the tv2
String textOutput = "0";
//tv2.setText(textOutput);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//This is called BEFORE the text has changed
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//This is called WHENEVER the text has changed
}
});
}
Really thanks,
Barata
Hello again!!
I was watching some classes now on youtube, and I made some tests that almost worked for what I want.
In this code, I cant edit one EditText and show a message in the 3 situations, before, on and after change the text.... and I did changes in the TextView created with AFTER, but just changed to a simple word, a text. That worked perfectly.
Now I'm trying to make a simple math, but I'm making some mistake with numbers and texts. I just need to multiply the EditText for a number (0.7354988) and put the result in the TextView, so I would convert CV to kW, but it gives me a message that I cant do it. I create one double CVtokWfactor with that value, but I'm not sure if I did it right.
this is the error:
Error44, 49) error: bad operand types for binary operator '*'
first type: EditText
second type: double
Below the JAVA:
Code:
package com.example.tbarata.textvalidation;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class TextValidation extends Activity implements TextWatcher{
EditText ed1;
TextView tv2;
double CVtokWfactor = 0.7354988;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_validation);
ed1=(EditText) findViewById(R.id.editText1);
ed1.addTextChangedListener(this);
tv2=(TextView) findViewById(R.id.textView2);
}
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
Toast.makeText(this, "before", Toast.LENGTH_SHORT).show();
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
Toast.makeText(this, "on change", Toast.LENGTH_SHORT).show();
}
@Override
public void afterTextChanged(Editable editable) {
Toast.makeText(this, "after", Toast.LENGTH_SHORT).show();
tv2.setText(String.format("%.2f", (ed1 * CVtokWfactor)));
}
}
What should I change to multiply these numbers ?
Thanks again.
Barata
Hello
For your first reply:
You have to put the code with the EditText inside the onCreate method. You made it work in the above code that you posted (outside onCreate) because you implemented the TextWatcher interface. You could avoid that by adding the code related with TextWatcher inside the onCreate method as I posted above
For your second reply:
In the afterTextChanged method, at
Code:
tv2.setText(String.format("%.2f", (ed1 * CVtokWfactor)));
You multiply the EditText ed1 with the double CVtokWfactor. You can't multiply an EditText with a number. The operand * needs numbers (int, double, float, etc )
You need to get the text of the ed1, convert it to double (I suppose edittext has double number) and then multiply, like this:
Code:
tv2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
Also I recommend to remove the Toasts from the methods beforeTextChanged, onTextChanged and afterTextChanged. They are called each time you type something on the EditText ed1.
If you still need help, feel free to ask
Hi!
Now it worked perfectly @MMDeveloper!! really thanks !
Agree with you about the Toast code, I forgot to delete it before paste here, it was just a test to see the events
About the way of using the TextWatcher, should I use the first way that you said, for some specific reason or basically both are the same ?
And now that's working, came the idea to improve the math, for an easy way of using it.
Now I can convert power in CV to kW, but lets say that I have one value in kW already, and need to convert to CV, would be posible using this same code/activity ? So I would convert in the same activity both units. Or, its gonna be some redundant thing ? My idea to save space, is use just the 2 fields, without one third to get the result.
This is the code now, already changed for a second EditText and not TextView anymore, until now it's working to convert the unit CV to kW, just when I clean out the EditTex1 field, the EditText2 keeps the conversion from the last number in the EditText1. Actually it's not a problem for now, the important is just convert it
Code:
public class Calc001Activity extends Activity implements TextWatcher {
EditText ed1;
EditText ed2;
double CVtokWfactor = 0.7354988;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc001);
ed1=(EditText) findViewById(R.id.editText1);
ed1.addTextChangedListener(this);
ed2=(EditText) findViewById(R.id.editText2);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
try {
ed2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
}
catch (NumberFormatException e) {}
}
}
Thanks in advanced.
Barata.
Let's fix the issue with the old conversion first
When you clear the ed1 your
Code:
ed2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
}
should cause your app to crash, because Double conversion from an empty string would throw the NumberFormatException.
You are already catching it so it silently ignores it, and the ed2 is not updated.
To solve this just make a check:
Code:
@Override
public void afterTextChanged(Editable s) {
if(doNoEnterEd1==true){
return;
}
doNotEnterEd2 = true;
try {
if(ed1.getText().toString().equals("")){
ed2.setText("");
}
else{
ed2.setText(String.format("%.2f", (Double.parseDouble(ed1.getText().toString()) * CVtokWfactor)));
}
}
catch (NumberFormatException e) {}
doNotEnterEd2 = false;
}
Now it should clear the ed2 too, when you clear the ed1.
Now for the TextWatcher, you should do it as I mentioned in my first reply, only for having a separate TextWatcher for each EditText, but there is no problem with implenting the TextWatcher, as you did. Just for code clarity. Furthermore, for code clarity (and reusability), the text watcher should be in a separate Java class, but no need for such a small application So you are ok with that.
You can easily do the reverse conversion (from ed2 to ed1) as follows:
Inside your class outside any method, where you declared your EditText add:
Code:
boolean doNotEnterEd1=false;
boolean doNotEnterEd2=false;
in the onCreate method:
Code:
ed2=(EditText) findViewById(R.id.editText2);
ed2.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
if(doNoEnterEd2==true){
return;
}
doNotEnterEd1 = true;
try {
if(ed2.getText().toString().equals("")){
ed1.setText("");
}
else{
ed1.setText(String.format("%.2f", (Double.parseDouble(ed2.getText().toString()) * CVtokWfactor))); //Here do the conversion as you like, replace CVtokWfactor.
}
}
catch (NumberFormatException e) {}
doNotEnterEd1=false;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
I think it should work like intended now.
If you still encounter a problem feel free to ask
Hello!
@MMDeveloper, thanks man!!!
The code is working perfectly!! I changed the code as in the first reply and with these last modifications, its 100%!
Now I'm gonna improve the layout and add the others inputs for the math, but the base code is fully working
Really thanks for you time, helping me.
As reference, this is my code now (still without the improvement):
Code:
package com.example.barata.calc001;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class Calc001Activity_002 extends Activity {
double CVtokWfactor_2 = 0.7354988;
boolean doNotEnterEd1=false;
boolean doNotEnterEd2=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calc001_activity_002);
final EditText ed1_2 = (EditText) findViewById(R.id.editText02_1);
final EditText ed2_2 = (EditText) findViewById(R.id.editText02_2);
ed1_2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(doNotEnterEd1==true){
return;
}
doNotEnterEd1 = true;
try {
if(ed1_2.getText().toString().equals("")){
ed2_2.setText("");
}
else{
ed2_2.setText(String.format("%.3f", (Double.parseDouble(ed1_2.getText().toString()) * CVtokWfactor_2)));
}
}
catch (NumberFormatException e) {}
doNotEnterEd2 = false;
}
});
ed2_2.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
if(doNotEnterEd2==true){
return;
}
doNotEnterEd1 = true;
try {
if(ed2_2.getText().toString().equals("")){
ed1_2.setText("");
}
else{
ed1_2.setText(String.format("%.3f", (Double.parseDouble(ed2_2.getText().toString()) * CVtokWfactor_2))); //Here do the conversion as you like, replace CVtokWfactor.
}
}
catch (NumberFormatException e) {}
doNotEnterEd1=false;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
}
public void vemPara001(View view) {
Intent vem001 = new Intent(this, Calc001Activity.class);
startActivity(vem001);
finish();
}
public void vaiPara003(View view) {
Intent vai003 = new Intent(this, Calc001Activity_003.class);
startActivity(vai003);
finish();
}
}
Thanks again!
barata.
Hi again!!
Sorry bring this topic back, but I gave up of doind my sliding tabs to get a nice layout in this app... so I got this one with a sliding menu from left, the I thought would be nice to use.
This is the link:
https://github.com/JulienGenoud/android-percent-support-lib-sample
Actually, the focus on its sample is to use the PERCENT lib, but that I don't care, just need to use the sliding menu;
I tried to replace the view1.xml for that with the code above (with textWatcher) and created one view_1.java with the codes, but nothing happens when I type a number in the editText....
Because the app uses a Drawer or fragment, should I change the way of doing that and automatically update the fields?
Thanks again!
Barata
hello,
i have a problem with my app, i am trying to add NFC for a point system, like get points at a NFC tag.
my java.start (without links)
package plopmenzinc.nsapp;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.nfc.NfcAdapter;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class Start extends AppCompatActivity {
int number = 0;
public void onClickBtn(View v)
{
TextView var = (TextView) findViewById(R.id.score);
number++;
String disp = Integer.toString(number);
var.setText(disp);
}
public class MainActivity extends Activity {
public static final String MIME_TEXT_PLAIN = "text/plain";
public static final String TAG = "NfcDemo";
private TextView mTextView;
private NfcAdapter mNfcAdapter;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter == null) {
// Stop here, we definitely need NFC
Toast.makeText(this, "This device doesn't support NFC.", Toast.LENGTH_LONG).show();
finish();
return;
}
if (!mNfcAdapter.isEnabled()) {
mTextView.setText("NFC is disabled.");
}
handleIntent(getIntent());
}
@override
protected void onResume() {
super.onResume();
/**
* It's important, that the activity is in the foreground (resumed). Otherwise
* an IllegalStateException is thrown.
*/
setupForegroundDispatch(this, mNfcAdapter);
}
@override
protected void onPause() {
/**
* Call this before onPause, otherwise an IllegalArgumentException is thrown as well.
*/
stopForegroundDispatch(this, mNfcAdapter);
super.onPause();
}
@override
protected void onNewIntent(Intent intent) {
/**
* This method gets called, when a new Intent gets associated with the current activity instance.
* Instead of creating a new activity, onNewIntent will be called. For more information have a look
* at the documentation.
*
* In our case this method gets called, when the user attaches a Tag to the device.
*/
handleIntent(intent);
}
private void handleIntent(Intent intent) {
TextView var = (TextView) findViewById(R.id.score);
number++;
String disp = Integer.toString(number);
var.setText(disp);
}
/**
* @param activity The corresponding {@link Activity} requesting the foreground dispatch.
* @param adapter The {@link NfcAdapter} used for the foreground dispatch.
*/
public void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
IntentFilter[] filters = new IntentFilter[1];
String[][] techList = new String[][]{};
// Notice that this is the same filter as in our manifest.
filters[0] = new IntentFilter();
filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
filters[0].addCategory(Intent.CATEGORY_DEFAULT);
try {
filters[0].addDataType(MIME_TEXT_PLAIN);
} catch (IntentFilter.MalformedMimeTypeException e) {
throw new RuntimeException("Check your mime type.");
}
adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
public void stopForegroundDispatch(final Activity activity, NfcAdapter adapter) {
adapter.disableForegroundDispatch(activity);
}
}
}
my activity: (without links)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="(link)"
xmlns:tools="(link)"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="vertical"
androidaddingBottom="@dimen/activity_vertical_margin"
androidaddingLeft="@dimen/activity_horizontal_margin"
androidaddingRight="@dimen/activity_horizontal_margin"
androidaddingTop="@dimen/activity_vertical_margin"
tools:context="plopmenzinc.nsapp.Start"
android:saveEnabled="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Uw aantal punten:"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="50dp"
android:singleLine="true"
android:textColor="#FF2646B0"
android:textSize="22sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/disp"
android:id="@+id/score"
android:layout_alignBottom="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:textSize="22sp" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add Points"
androidnClick="onClickBtn"
android:layout_marginBottom="73dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
if you need other files/scripts, just ask.
thank you
EDIT: removed the public class MainActivity extends Activity {} and works perfect now
Goodmorning ,
I was dabbling with the parser of a web page through Android Studio, the problem is that the code I implemented can't take what i want, I'll explain:
on a website is a web page with the following html:
HTML:
</style>
</head>
<body>
<h1>TITLE PAGE</h1>
<h2><em></em></h2>
<h2>La data prossimae è:</h2>
<p><br />Lunedi 10/10/2016<br />Orario 13.00 - 18.00</p><input type="button" name="chiudi" value="Chiudi" onclick="javascript: self.close();" />
</body>
</html>
With the class JSOUP I'd like to take just the date which is enclosed within <p>, that is, "10/10/2016", is it possible? for now I could only print the page title or the entire text of the page.
here is the class code:
HTML:
package inducesmile.com.androidjsouphtmlparser;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
private Document htmlDocument;
private String htmlPageUrl = "website";
private TextView parsedHtmlNode;
private String htmlContentInStringFormat;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_livepage);
parsedHtmlNode = (TextView)findViewById(R.id.html_content);
Button htmlTitleButton = (Button)findViewById(R.id.button);
htmlTitleButton.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
JsoupAsyncTask jsoupAsyncTask = new JsoupAsyncTask();
jsoupAsyncTask.execute();
}
});
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_livepage, menu);
return true;
}
[user=439709]@override[/user]
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class JsoupAsyncTask extends AsyncTask<Void, Void, Void> {
[user=439709]@override[/user]
protected void onPreExecute() {
super.onPreExecute();
}
[user=439709]@override[/user]
protected Void doInBackground(Void... params) {
try {
htmlDocument = Jsoup.connect(htmlPageUrl).get();
htmlContentInStringFormat = htmlDocument.text();
// htmlDocument.title();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
[user=439709]@override[/user]
protected void onPostExecute(Void result) {
parsedHtmlNode.setText(htmlContentInStringFormat);
}
}
}
Thanks to everyone for help!