Store image as value in Android Studio - android

This is a code when user choose one image and will run this coding (finish()), if choose wrong image then do not run the finish() .
but i dont know how to make the image as a value , how i select the drawable a or b or c and link to this function
if(eyeDected)
{
if(detectedFrame > 25)
{
eyeDected = false;
detectedFrame = 0;
finish();
} else {
detectedFrame++;
Log.d("UNLOCK:", String.valueOf(detectedFrame));
}
} else {
eyeDected = true;
detectedFrame++;
Log.d("UNLOCK:", String.valueOf(detectedFrame));
}
I want to ask about how to store the drawble/image into value?
i'm developing a lock screen application , when user choose the correct image will execute the unlock function
This is a layout showing 3 images and give user choose one images inside a lock screen.
In the setting , i'll let user to choose one image as the correct image that will execute the code
set_image.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/new_build_resize_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/setting">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Image "
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="38dp"
android:textColor="#color/abc_primary_text_material_light" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select one graphical passcode as your lock screen."
android:id="#+id/textView2"
android:textSize="22dp"
android:textColor="#1547bb"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="135dp"
android:layout_height="140dp"
android:src="#drawable/a"
android:id="#+id/imageButton1"
android:layout_above="#+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2" />
<ImageButton
android:layout_width="126dp"
android:layout_height="126dp"
android:src="#drawable/b"
android:id="#+id/imageView2"
android:layout_above="#+id/imageView3"
android:layout_alignParentLeft="true" />
<ImageButton
android:layout_width="126dp"
android:layout_height="126dp"
android:src="#drawable/c"
android:id="#+id/imageView3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="46dp" />
</RelativeLayout>

Related

Android studio error: resource not found Exception

i have a problem with my app: i'm using crashlytics by Fabric, (my app is pubblishes in the play store) to have log of possible crash, and i have this error ".. MainActivity: android.content.res.Resource$NotFoundException:Resource ID#0x7f09001b"
(Crashlytics say to me that the device is a samsung galaxy s4 with Android 5.1 and root )
CrashLytics screen
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.activity_main); <---- LINE 102 THAT GIVE
THE ERROR , ACCORDING TO
CRASHLYTICS
ping = (ImageButton)findViewById(R.id.ping);
internet =(TextView)findViewById(R.id.Internet);
banda5Ghz =(TextView)findViewById(R.id.BandeSupp);
SpeedNet =(TextView)findViewById(R.id.VR);
ipv6 =(TextView)findViewById(R.id.showIPv6);
txVsegnale =(TextView)findViewById(R.id.intensità);
aggiorna = (ImageButton)findViewById(R.id.Aggiorna);
share = (ImageButton)findViewById(R.id.sharebtn);
clipboard = (ImageButton)findViewById(R.id.clipboard);
rating = (ImageButton)findViewById(R.id.ratebtn);
IP =(TextView)findViewById(R.id.IP);
showIPv4 =(TextView)findViewById(R.id.showIPv4);
// TextViewWifi =(TextView)findViewById(R.id.TextViewWifi);
TextViewwifi_info = (TextView)findViewById(R.id.wifi_info);
MacA = (TextView)findViewById(R.id.MacAdd);
//switch gestione notifiche
notifiche = (Switch)findViewById(R.id.switchNot);`
......
The same device crash 2 times in a short time, with same error.
My app is an app that show infos on your wifi connection, such as IP, network velocity, etc etc, also have system notification and widgets and a service that run in background .
I have also done different layout for different devices with different screen size and different screen dpi
My Layouts
No other logs from other device with same problem .I want to know if is a specific problem of this device ( may be related to root access given to this device ) or is a problem of my application.
Not sure if it is linked to this, but, i was tryeing to add split screen function to my app, and , adding android:resizeableActivity="true" to manifest, make app crash in the same code line, so, i solve by settings to false and not include split screen feature in my app.
I CONFIRMED THAT TRIEING TO USE SPLIT SCREEN GIVE ME THE SAME ERROR, SAME RESOURCE NOT FOUND EXCEPTION, how can i see which resource have this id ?
android.content.res.Resources$NotFoundException: Resource ID #0x7f09001b
THE APP Crash only in this case , no other crash, do i have to define a minimum width and weight to use split Screen ?
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ShowMyIp.utente.ShowMyIp.MainActivity">
<TextView
android:id="#+id/Internet"
android:layout_width="match_parent"
android:layout_height="225dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/roundcorner"
android:layout_marginTop="8dp"
android:paddingTop="27dp"
android:textColor="#646464"
android:textSize="13sp"
android:layout_marginLeft="7dp"
android:layout_marginRight="8dp"
android:textStyle="italic" />
<TextView
android:id="#+id/Internet2"
android:layout_width="match_parent"
android:layout_height="195dp"
android:layout_alignEnd="#+id/internet4"
android:layout_below="#+id/internet4"
android:layout_marginTop="14dp"
android:layout_marginLeft="7dp"
android:background="#drawable/roundcorner" />
<TextView
android:id="#+id/internet4"
android:layout_width="match_parent"
android:layout_height="195dp"
android:layout_alignStart="#+id/Internet"
android:layout_below="#+id/Internet"
android:layout_marginRight="8dp"
android:layout_marginTop="17dp"
android:background="#drawable/roundcorner"
android:textSize="13sp" />
<TextView
android:id="#+id/MacAdd"
android:layout_width="275dp"
android:layout_height="35dp"
android:layout_alignStart="#+id/txtMac"
android:layout_below="#+id/BandeSupp"
android:layout_marginTop="35dp"
android:textAlignment="viewStart"
android:textColor="#android:color/black"
android:textSize="15sp" />
<TextView
android:id="#+id/IP"
android:layout_width="150dp"
android:layout_height="45dp"
android:layout_alignBaseline="#+id/Internet"
android:layout_alignBottom="#+id/Internet"
android:layout_alignStart="#+id/internet4"
android:layout_marginStart="45dp"
android:text="IP Address"
android:textColor="#E1E140"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="#+id/showIPv4"
android:layout_width="230dp"
android:layout_height="45dp"
android:layout_alignStart="#+id/IP"
android:layout_below="#+id/intensità"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/wifi_info"
android:layout_width="220dp"
android:layout_height="55dp"
android:layout_alignStart="#+id/showIPv4"
android:layout_below="#+id/showIPv4"
android:text="Non Connesso"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="italic" />
<TextView
android:id="#+id/velocita"
android:layout_width="155dp"
android:layout_height="45dp"
android:layout_above="#+id/VR"
android:layout_alignEnd="#+id/txvIPV6"
android:text="Velocità rete"
android:textColor="#E1E140"
android:textSize="18sp"
android:textStyle="italic" />
<TextView
android:id="#+id/VR"
android:layout_width="135dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/wifi_info"
android:layout_alignEnd="#+id/velocita"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="italic" />
<ImageButton
android:id="#+id/Aggiorna"
android:layout_width="200dp"
android:layout_height="75dp"
android:layout_alignEnd="#+id/intensità"
android:layout_alignTop="#+id/Internet2"
android:layout_marginEnd="21dp"
android:layout_marginTop="56dp"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:textColor="#android:color/white"
app:srcCompat="#drawable/btn_aggiorna" />
<TextView
android:id="#+id/intensità"
android:layout_width="190dp"
android:layout_height="65dp"
android:layout_alignEnd="#+id/Internet"
android:layout_alignTop="#+id/IP"
android:layout_marginEnd="21dp"
android:textColor="#android:color/black"
android:textSize="18sp" />
<TextView
android:id="#+id/txtMac"
android:layout_width="140dp"
android:layout_height="35dp"
android:layout_alignStart="#+id/showIPv4"
android:layout_alignTop="#+id/internet4"
android:layout_marginTop="28dp"
android:text="MAC Address"
android:textColor="#E1E140"
android:textSize="18sp" />
<Switch
android:id="#+id/switchNot"
android:layout_width="145dp"
android:layout_height="85dp"
android:layout_alignStart="#+id/MacAdd"
android:layout_alignTop="#+id/Aggiorna"
android:layout_marginStart="28dp"
android:textColor="#E1E140"
android:textSize="18sp"
tools:text="Notifiche" />
<TextView
android:id="#+id/txvIPV6"
android:layout_width="75dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/txtMac"
android:layout_alignEnd="#+id/Aggiorna"
android:text="IPV6"
android:textColor="#E1E140"
android:textSize="18sp" />
<TextView
android:id="#+id/showIPv6"
android:layout_width="220dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/MacAdd"
android:layout_alignStart="#+id/Aggiorna"
android:textAlignment="viewStart"
android:textColor="#android:color/black"
android:textSize="17sp" />
<ImageButton
android:id="#+id/ratebtn"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignEnd="#+id/Internet2"
android:layout_alignParentBottom="true"
android:layout_marginBottom="22dp"
android:layout_marginEnd="10dp"
android:background="#android:color/transparent"
app:srcCompat="#drawable/rating_button"
android:scaleType="fitCenter"
/>
<ImageButton
android:id="#+id/sharebtn"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignTop="#+id/ratebtn"
android:layout_marginEnd="23dp"
android:layout_toStartOf="#+id/ratebtn"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:srcCompat="#drawable/share_button" />
<ImageButton
android:id="#+id/clipboard"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_alignTop="#+id/sharebtn"
android:layout_toStartOf="#+id/VR"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:srcCompat="#drawable/clipboard" />
<TextView
android:id="#+id/BandeSupp"
android:layout_width="130dp"
android:layout_height="55dp"
android:layout_alignTop="#+id/txvIPV6"
android:layout_toEndOf="#+id/showIPv4"
android:textColor="#android:color/black"
android:visibility="invisible"
android:textSize="17sp" />
<ImageButton
android:id="#+id/ping"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignBottom="#+id/clipboard"
android:layout_alignEnd="#+id/switchNot"
android:background="#android:color/transparent"
android:visibility="invisible"
app:srcCompat="#drawable/ping" />
</RelativeLayout>`
here is my layout (large-port-mdpi)
App still crash entering in split screen mode, with "no found exception ..." ; i've made another simple app , following Android developer guide to make multiview support, and this app work, no problem when entering in split screen, , i only added to the Manifest same code i wrote for this app " android:resizeableActivity="true"". Anyone know about to resolve this error? why my app, dosen't find layout resource entering in split screen mode??
Check your MainActivity Layout Xml in Text Format, There Has to be Line with a Yellow Warning on it, Or a Red Line.
Check the Layout Xml, And Then,
Check If You Missed Something Like LinearLayout Being RelativeLayout and you Declared it with this mistake.
Then Check If You've Used Anything like below:
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myRelativeLayout.getLayoutParams();
LinearLayout.LayoutParams Param1 = (LinearLayout.LayoutParams) myLinearLayout.getLayoutParams();
If Yes, Reply me and I'll tell you what to do.

Any Skin Selector Android library

Are there any android library that do:
Shows drawables in either a grid or scroll view.
Allows user to select one of the images and shows his selection.
Allows me to get the selected drawable and show it to the user.
Please see the screenshots to see what I'm trying to achieve.
I have done something like you are thinking about. I will show you that if is useful to you (I think will be, but you must adapt this):
Context: I have created a simple game based in Space Invaders. My game has a main menu (main activity) where the player can press 'PLAY' or scan elect some 'OPTIONS', though a popup.
App main menu image
1 screen: Main menu.
2 screen: Popup appears when I press 'OPTIONS' button. This popup let me choose graphic options (change game background, ally spaceship model and enemy spaship model).
MainActivity.java
optionBoton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
soundMenu.start();
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View viewPopup = inflater.inflate(R.layout.popup_activity, null);
popup = new PopupWindow(
viewPopup,
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
popup.showAtLocation(layoutPrincipal, Gravity.BOTTOM, 0, 0);
ImageButton closePop = (ImageButton) vistaPopup.findViewById(R.id.volver_boton);
closePop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
soundMenu.start();
popup.dismiss();
optionBoton.setVisibility(View.VISIBLE);
}
});
optionBoton.setVisibility(View.INVISIBLE);
}
});
This code will be inside onCreate method.
Now, you need to design your own XML popup (if you decide to create a popup). Showing a popup is easy, clean and dynamic way to change the graphic options.
popup_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#839ceaac"
android:orientation="vertical">
<ImageButton
android:id="#+id/volver_boton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:layout_marginTop="3dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:src="#drawable/wcerrar" />
<TextView
android:id="#+id/options_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="6dp"
android:layout_marginTop="5dp"
android:text="Opciones gráficas"
android:textSize="20dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#id/options_title"
android:background="#9dc8a6" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/options_title"
android:layout_marginBottom="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/back_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Fondo"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/back_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/back_title"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadBack"
android:scaleType="centerCrop"
android:src="#drawable/fondo" />
<ImageView
android:id="#+id/back_2"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/back_1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadBack"
android:scaleType="centerCrop"
android:src="#drawable/fondo1" />
<ImageView
android:id="#+id/back_3"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/back_2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadBack"
android:scaleType="centerCrop"
android:src="#drawable/fondo3" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/spaceship_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Spaceship"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/spaceship_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/spaceship_title"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadSpaceship"
android:src="#drawable/diseno11" />
<ImageView
android:id="#+id/spaceship_2"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/spaceship_1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadSpaceship"
android:src="#drawable/diseno21" />
<ImageView
android:id="#+id/spaceship_3"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/spaceship_2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadSpaceship"
android:src="#drawable/diseno31" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/enemy_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Enemies"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/enemy_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/enemy_title"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="uploadEnemy"
android:rotation="180"
android:src="#drawable/enemigodiseno11" />
<ImageView
android:id="#+id/enemy_2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_below="#id/enemy_1"
android:layout_marginBottom="3dp"
android:layout_centerHorizontal="true"
android:src="#drawable/enemigodiseno21"
android:onClick="uploadEnemy"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Anyway, if you choose to don't use a popup, I will show you how you can send some data to another activity in Android development:
When you press on a graphic option, look at the call "android:onclick". This allows to call a java method to capture the option selected.
Look a simple example of this:
Method example
public void uploadBack(View view) {
switch (view.getId()) {
case R.id.back_1:
result[0] = "back";
break;
case R.id.back_2:
result[0] = "back1";
break;
case R.id.back_3:
result[0] = "back3";
break;
}
}
As you can see, I have an array of Strings with 3 positions. When I click an ImageView, I call the method wich changes the result[i] value. When I press 'PLAY' and I call the game activity, I use putExtra method to send these options and change the game settings.
I hope this serve as a help for your problem.
Have a nice day!

Saving state of the view

Is there an easy way to save a whole viewgroup with its data together? For example if initially i have this view and during the app run some of the view's background image changes, some views become invisible, or its' text changes, etc. How can I save the state of the view, in case user quits app?
<RelativeLayout android:layout_width="wrap_content" android:id="#+id/water_room_common"
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
>
<!-- storage layout -->
<View android:id="#+id/gap" android:layout_width="wrap_content"
android:layout_height="0dip" android:layout_alignParentBottom="true" />
<RelativeLayout android:id="#+id/storage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_above="#id/gap" android:layout_marginBottom="10dp"
android:layout_marginRight="27dp" android:layout_marginLeft="10dp"
android:layout_toLeftOf="#id/bag" android:orientation="horizontal"
>
<ImageButton android:id="#+id/ImageButton02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton01"
android:background="#drawable/single_square" android:onClick="itemSelected" />
<ImageButton android:id="#+id/ImageButton03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_centerHorizontal="true" android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/ImageButton02" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton03"
android:adjustViewBounds="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton05"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton04"
android:adjustViewBounds="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton06"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/ImageButton01"
android:layout_marginRight="16dp" android:layout_toLeftOf="#+id/ImageButton05"
android:adjustViewBounds="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
<ImageButton android:id="#+id/ImageButton01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:background="#drawable/single_square"
android:onClick="itemSelected"
/>
</RelativeLayout>
<ImageButton android:id="#+id/bag" android:layout_width="65dp"
android:layout_height="65dp" android:layout_alignBottom="#+id/storage"
android:layout_alignParentRight="true" android:layout_marginRight="10dp"
android:adjustViewBounds="true"
android:onClick="bagClicked"/>
<ImageButton android:id="#+id/left" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="#+id/storage"
android:layout_centerVertical="true" android:background="#null"
android:onClick="previousWall" android:src="#drawable/left" />
<ImageButton android:id="#+id/right" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignRight="#id/bag"
android:layout_centerVertical="true" android:background="#null"
android:onClick="nextWall" android:src="#drawable/right" />
</RelativeLayout>
See this answer. You need to override onSaveInstanceState for transient changes or override onPause and onResume for permanent changes.
Read the API guide here
Update
This is a summary of this training
Picture this scenario. You have a notepad app. On the homescreen, the user has a list of recently created notes (NoteList Activity) and the user can choose to create a new note or edit an existing note and changes will be stored in a database.
When the user clicks on an item brings another activity (NoteEditActivity) to the foreground. If the user is in the process of editting a note and the NoteEditActivity loses focus for some reason (e.g a call comes in or the user just decides to switch to another app without clicking the "confirm button") the NoteEditActivity goes from being focused to being paused and then shortly after it is stopped.
To prevent the user from loosing the current edit, you need to call onPause where you would want to save any changes to the database. Now if the app is in the stopped (onStop) and the user returns to the edit it will not go through onCreate but rather through onResume which is where you want to "resume" from where the user left.
This picture should further explain.
Notice how onResume gets called every time the activity is about to be focused and not onCreate.
You can follow the training above for better understanding.

How to increase size of posted pictures from facebook api?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dip"
android:background="#drawable/greybox"
>
<ImageView
android:id="#+id/profile_pic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/profile_pic">
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Kumar"
android:textSize="18dp"
android:textColor="#4c3f38"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/msg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_below="#+id/name"
android:textColor="#7b7674"
/>
<LinearLayout
android:id="#+id/picpostlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="5dp"
android:layout_below="#+id/msg"
android:orientation="vertical" >
<ImageView
android:id="#+id/picpost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#null" />
</LinearLayout>
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/picpostlayout"
android:layout_alignParentRight="true"
android:textColor="#000000"
/>
</RelativeLayout>
</RelativeLayout>
Here is my complete xml.I am using the linearlayout to show the posted picture,but it is still showing very small size.I used two relative layouts, one for complete xml and another for name,message,postpicture.
Here is also my screenshot to the above given xml file.I am getting the large image but I cant able to show the same size,it is showing very small size.
I got an post picture from facebook api,I am getting very large image as I used _n.jpg,but when I tried to display using imageview it is showing very small size.
][1]
[1]: http://i.stack.imgur.com/63nTO.png
Here is the code of getting posted picture from facebook api.If the post object has picture field then I get that picture and changed that into large image and I added that to my ArrayList pic.
if(jsonObject.has("picture"))
{
String fetchedURL = jsonObject.getString("picture");
String getFeedPicture = fetchedURL.replaceAll("_s.jpg", "_n.jpg");
pic.add(getFeedPicture);
}
Then I send that ArrayList to my Adapter where I set that image to imageview by sending to imageloader class.
Here is my loader class reference imageloader and I am setting image to imageview.I am setting this in my adapter class.
imageLoader.DisplayImage(postimage.get(position).replace(" ", "%20"), postimg) ;
Make this modification to your current code:
String fetchedURL = JOFeeds.getString("picture");
String getFeedPicture = fetchedURL.replaceAll("_s.jpg", "_n.jpg");
pic.add(getFeedPicture);
This is the simplest way to get a better quality picture from your Feeds. The whole point of this piece of code is that by default, the Facebook API returns a small version of the image. By replacing the _s.jpg with _n.jpg gives you a bigger image.
I use this code throughout my application and it works like a charm every single time.
And the corresponding code for this is:
<LinearLayout
android:id="#+id/linlaFeedPicture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_margin="1dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgvwFeedPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#null" />
</LinearLayout>

How do I add a graphic overlay on an activity? Android

I am trying to have a picture show up in the middle of the screen guiding people what to press (eg an arrow to a button). What do I use so that the arrow design will show up at the appropriate spot and dissapear after I do something (like press the screen)
Thanks!
EDIT
Here is the xml layout for one of my activities, note the imageview at the bottom, it shows the picture in the front
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="45dp" android:background="#drawable/mytitlebackground" android:id="#+id/relativeLayout1">
<ImageButton android:id="#+id/btnAddFriends"
android:layout_width="wrap_content" android:src="#android:drawable/ic_input_add"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentRight="true"></ImageButton>
<TextView android:id="#+id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="#string/imTracking" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerVertical="true" android:layout_centerHorizontal="true"></TextView>
</RelativeLayout>
<Button android:id="#+id/btnUpdateLocation" android:text="Update Location"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"></Button>
<ImageButton android:src="#drawable/mapbutton"
android:layout_width="wrap_content" android:id="#+id/btnMaps"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_alignTop="#+id/btnUpdateLocation"></ImageButton>
<ImageButton android:text="Refresh"
android:src="#android:drawable/stat_notify_sync" android:layout_width="wrap_content"
android:id="#+id/btnRefresh" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"></ImageButton>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="#+id/relativeLayout1"
android:layout_alignParentLeft="true" android:layout_above="#+id/btnUpdateLocation" android:id="#+id/linearLayout1">
<ListView android:id="#+id/imtrackinglistview"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_weight="1"></ListView>
</LinearLayout>
<ImageView android:id="#+id/iVImtrackingpopup" android:layout_width="300dp" android:layout_height="330dp" android:src="#drawable/imtrackinghelp_en" android:layout_centerVertical="true" android:layout_centerHorizontal="true"></ImageView>
When I try to "click" the relative layout to make the image invisible, it doesn't work unless I click the top of the layout
RelativeLayout Imtrackingrelativelayout=(RelativeLayout) findViewById(R.id.relativeLayoutImtracking);
Imtrackingrelativelayout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ImageView imtrackingoverlay=(ImageView) findViewById(R.id.iVImtrackingpopup);
imtrackingoverlay.setVisibility(View.INVISIBLE);
}
});
make the image centre aligned and put click listener over root layout and on click make this image invisible......Better to use relative layout for this.....
Have you tried using the ShowcaseView library? It offers a more cleaner approach to what you are trying to achieve
Check out the project here:-
https://github.com/amlcurran/ShowcaseView

Categories

Resources