Android: How to obtain an overlay on top of acitivity - android

when my application is installed for the first time by the user , i want to explain him what each activity does (like a quick tip) , it should look like the below picture
it should have the cancel button , and should not repeat after the first install,
I need suggestion or any useful links ,how to implement it, Any help is appreciated.

You could use SharePreference to store the state whether or not user have viewed your instruction. Just add a boolean value named as 'instructionViewed' to SharePreference. Every time your application launched, check the value. If true, don't show instruction. If false, show instruction. When user click the cancel button, set the value to true.
SharePreference is a very easy-using class to help store some information.You could google how use it.
Hope this helpful.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testpage);
//Check SharePreference
boolean instructionViewed = checkInstrunctionState();
//If the instruction is not viewed, show instruction.
if(!instructionViewed){
RelativeLayout yourLayout = createYourOwnUi();
FrameLayout contentView = (FrameLayout)(getWindow().getDecorView().findViewById(android.R.id.content));
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(MATCH_PARENT,MATCH_PARENT);
contentView.addView(yourLayout, lp);
}
}

Related

Turbolinks 5 and Android: Fails when use file upload (webview)

Problem
When the user clicks on choose file, I intercept that click natively and I call the native view (screen 3 in the mockup).
After the user select the file he wants to upload, I need to "reload" the view in order to add the name of the file in the form, so the user can get the feedback that he selected the file correctly.
In order to do this, I'm calling onRestart with the following code:
#Override
protected void onRestart() {
super.onRestart();
// mCM is a variable to detect when the user is choosing a file.
if (null == mCM) {
// Since the webView is shared between activities, we need to tell Turbolinks
// to load the location from the previous activity upon restarting
TurbolinksSession.getDefault(this)
.activity(this)
.adapter(this)
.restoreWithCachedSnapshot(true)
.view(turbolinksView)
.visit(location);
}
}
As you can see, in this method when is uploading a file I do NOT reload the view using TurbolinksSession.
But if I don't call TurbolinksSession, Turbolinks never calls visitProposedToLocationWithAction.
Scenario
NOTE: Download the image if you want to see the image bigger.
What am I missing? Is there a way to solve this problem and get the expected result?
In this 2 issues you can find a solution and resolution of the problem (read it in this order):
https://github.com/turbolinks/turbolinks-android/issues/53
https://github.com/turbolinks/turbolinks-android/issues/65
https://github.com/turbolinks/turbolinks/issues/88

Android Swipe Images Intro Screen on First Run

I've been looking around a lot lately but haven't really found much on this.
I'm making my third Android app and I'm looking to implement an intro screen on first run of the app where a series of images are shown explaining the apps functionality and the idea behind it; you can swipe the images left or right and at the last image you get to the app by swiping.
I really like the sort of thing they have done with the CamScanner app but despite my searching I have no idea how to implement it other knowing a little bit about some people referring to Fragments. Any help would be appreciated greatly and since we need better UI on Android, a good answer would help a lot of developers take the cue! :)
create a method to show popup window. show images in a scroll view in that popup. at last image set touch listener to dismiss that popup.
and call that method from onResume method of your Activity like this
protected void onResume(){
super.onResume();
SharedPreferences pref = getSharedPreferences(MyPrefs, MODE_PRIVATE);
boolean b = pref.getBoolean("FirstTime",true);
if(b)
{ new Handler().postDelayed(new Runnable() {
public void run() {
showIntroPopup();
}
}, 100);
}
}
in that popup set "FirstTime" boolean to false in SharedPreferences.

Window Focus Disable in Android

I am stuck in a scenario. I have a login Form. I want to show it as disabled for some users. I can get that users but I dont know how to remove the focus from the window.
//to check whether the current user is administrator or not
public void checkAdministrator(){
String owner = ParseValues.parsedGroupList.get(indexofGroup).getGroup_owner();
String currentUser = CCMStaticVariable.loginUserId+"#abc.com";
if(owner.equalsIgnoreCase(currentUser)){
administrator=true;
}
else{
administrator=false;
}
}
Now -
if(!administrator){
//here I want to disable the whole Activity, I just want to show the activity in disabled state
}
First get your parent layout from your login xml and try this
parentLayout.setEnabled(false);

Android: SharedPreference errors after force close

I'm getting some weird effects after I force close my app. When the app is closed with finish(), everything is fine. I have some variables saved in a sharedPreferences so when the app is loaded again, it can restore those variables into the UI. However, if I force close the app and THEN try to continue where it had left off, some variables start "acting funny". By that I mean (in onCreate) I check to see if a string, loaded from the sharedPreferences, equals a value (crunched down version):
String namec;
private static final String TAG = "MyActivity";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//namec was set as "forest" in a previous activity
//which is bypassed if the user selects continue
//from the main menu
SharedPreferences pathtaken = getSharedPreferences("pathtakenpref", MODE_WORLD_READABLE);
namec = pathtaken.getString("namec", "Unknown");
ImageView v1 = (ImageView) findViewById(R.id.pathpic1);
RelativeLayout v2 = (RelativeLayout) findViewById(R.id.pathmain);
Log.i(TAG, "namec= " + namec);
if(namec == "forest"){
v1.setImageResource(R.drawable.forest);
v2.setBackgroundResource(R.drawable.forestrepeat);
}
}
What happens here is namec, does in fact, equal "forest". I send the value to the log and it shows the variable exactly as it should be ("forest"). Yet it won't run the code inside of the if{}. It's giving me nightmares. I've been stuck on this for a week!
In the same code, I load a different set of sharedPreferences (labeled as TRHprefs) and each one of those (6 integers and 3 strings) load up and display just fine. I even add an if{} to test 1 string and 1 integer from TRHprefs... they both came back true.
Q.1: Is there anything that can cause my sharedPreferences xml to become, somehow, corrupted on a force close?
Q.2: Is there a way for me to view the xml file before and after I use force close to help debug the situation. Thanks so much!
Its a String. Try this:
if("forest".equals(namec)){
If you want to compare two String you need to use this:
if(namec.equals("forest")){
v1.setImageResource(R.drawable.forest);
v2.setBackgroundResource(R.drawable.forestrepeat);
}

How to accept dialog in unit testing?

I have a unit test that opens up a custom dialog and enters some text. This works, but I am unable to accept the dialog or get hold of the ok button. Please can anyone tell me how to automate the dialog acceptance using junit.
ActivityMonitor activityMonitor = instrumentation.addMonitor(
EditItem.class.getName(), null, false);
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
instrumentation.invokeContextMenuAction(gridList, R.id.add, 0);
Activity activity = instrumentation.waitForMonitorWithTimeout(
activityMonitor, 10);
assertNotNull("Make sure the edit item activity was called", activity);
assertEquals("Make sure the edit item activity was called",
EditItem.class, activity.getClass());
final TextView nameView = (TextView) activity.findViewById(R.id.name);
// this opens the dialog
TouchUtils.clickView(this, nameView);
// this adds some text
for (int i = 0; i < 3; i++)
{
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_X);
}
// here I would like to accept the ok button on the dialog
OK I seem to have worked round this with a combination of key presses
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
The problem is now I can't tell when the dialog has finished being dismissed and returned to the parent Activity to continue the test with a
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Go a work around for this too now:
instrumentation.waitForIdleSync();
instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Seems a bit clunky, is this how you are supposed to use these tools?
I'm having the same problem. What it looks like is that you will have to create a custom dialog. This will allow you to retrieve the buttons you added using the findViewById(). Here is a link that I found that might get you on the right path.
http://www.mkyong.com/android/android-custom-dialog-example/

Categories

Resources