quickly change Android system language - java

I'm studying mandarin and want to change the language of my Android smartphone (Sony Xperia) between english/mandarin (or english/mandarin/portuguese/spanish) faster than using the default system settings. The way it is, I have to enter settings, scroll to the middle of it (which is slower than if it was on the beginning or end of the list), click Language & input, click language, have to scroll all the way down to 中文 (it should already be at the top, among the "recently used languages", but only my native language is always there), click 中文 and finally click ok.
I would like to reduce those 6+ clicks to a single button in the quick settings area (there is space for 4 more icons): when the phone is in a language, a tap on the icon would change to the next language, holding the icon would open a menu to add/remove languages/change order/etc.
I'm new to Android development, so I don't know if it's possible for an app to change the system language (need root privileges? I want it for myself, even if I won't be allowed to share it on Google Play, for instance). I've seen many answers on how to change an app language, that's not what I'm looking for. I also found many apps in Google Play, all of them promising to "quick toggle system language" etc, but none of them worked on my device. The closest I got was this, but looks like a dead thread.
So, is it possible? If so, where is the documentation?

I think this is what you might looking for!!!
If you would like to have your own application you can try this app i just created for you here!!!
Language Picker Widget
The Java Code
public class MainActivity extends Activity {
private Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.add_button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//in the line below it tells it to go to the language selection list
Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
startActivity(intent);
MainActivity.this.finish();
}
});
}
}
The Layout File
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change System Language"
android:id="#+id/add_button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
You can start a project in eclipse, use the codes above for the activity and the layout and then test it on the emulator

Related

How to change the action bar color and open a file on click?

I'm working now on an app for Android and there are two things that I don't know how to do.
I want to change the colour of the action bar at the request of the user, so I want to change it dynamically. I see some answers that say that I need to use:
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#004D40")));
But for some reason, it does not work for me.
I've added to my app option to download a file, but I do it in an unusual way so it does not create a notification when the download is complete. I want to give my user an easy way to get to the file. Can I create a button that opens the file when clicked?
Thanks!
1) For that I would recommend you having Example here Toolbar View and set it as your Actionbar. Just add this view at the top:
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
And then in Activity
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
After this you can change everything you want to the view myToolbar. Set background color etc. It will work. Using just Actionbar is old and depricated approach.
2) Yes you can, it is like opening new Activity with intent. Android has some inbuilt Intent Action Type which helps you to Open or View specific files, but for this you need to know which type of file you are going to handle.
Suppose If you have file type which categorized in document type you can use,
ACTION_OPEN_DOCUMENT with specific MIME_TYPE (Android 4.4 or Higher)
or If you going to handle some media file (Audio/Video)
you can use,
ACTION_VIEW
To identify MIME_TYPE of specific file you can use function
guessContentTypeFromName (String url)Link
Or getMimeTypeFromExtension(String extension)Link
Hope this helps :)
You can't change the color because you should call getSupportActionBar() and it's also for api >11;
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.black)‌​));
or
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#004D40")​));
About your second question, we need more info and your code where you download file. You totally can access files onClick but you need to know the file type and the directory where you store the files and target api to check runtime permissions for example
I suggest you ask another question with all your code and this info

Android including XML and their Java class

I am making an app where I have a few menus (about 7 of them) and a starting screen that is it's own menu.
To make things easier to read, I've decided I want to separate each menu and the starting screen from the main activity and include them when the app runs. But I'd like to include a java class per XML file.
What I have so far is a starting page called activity_start_page.xml it has it's own java class called StartPage.java. This all works fine and dandy.
Inside of this start page, I have included an xml layout called part_start_scroll.xml and I'd like to have it's java included as well, part_start_scroll.java.
On top of both of these, I'd like to do the same thing with each setting sub section. I'll have all of the subsections like so:
part_settings_camera.xml
part_settings_email.xml
part_settings_security.xml
etc...
I'd like to include each one of these as well as a java class that will accompany them.
My XML file for activity_start_page includes all of the layouts:
<ViewFlipper
android:layout_width="0dp"
android:layout_weight=".75"
android:layout_height="match_parent"
android:id="#+id/viewFlipper"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<include layout="#layout/part_settings_session" android:id="#+id/part_settings_session"/>
<include layout="#layout/part_settings_camera" android:id="#+id/part_settings_camera"/>
<include layout="#layout/part_settings_security" android:id="#+id/part_settings_security"/>
<include layout="#layout/part_settings_social" android:id="#+id/part_settings_social"/>
<include layout="#layout/part_settings_printer" android:id="#+id/part_settings_printer"/>
<include layout="#layout/part_settings_email" android:id="#+id/part_settings_email"/>
<include layout="#layout/part_settings_about" android:id="#+id/part_settings_about"/>
</ViewFlipper>
and the StartPage.java handles the flipper to show the specific view depending on what menu item was clicked:
//One of these for each menu button
menu_about.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
viewFlipper.setDisplayedChild(6);
...
}
});
All of this works, except for the Java that accompanies each layout.
In my StartPage.java, I tried to use startActivity() to include the java, but it only works on one java class and not multiples. I got this from another question I asked earlier:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(StartPage.this, part_start_scroll.class));
startActivity(new Intent(StartPage.this, part_settings_session.class));
finish();
}
}, 1000);
The above does not work, but if I were to do just a single class, it works just fine.
So my ultimate question is: How do I include all of these other java files so I can compartmentalize my code? Second to that, but should have no bearing on the answer is: Is this inefficient?

How to add button to Google Play store in bottom corner of Android App?

I'm putting together a simple Android app and I wanted to add a button to one of the bottom corners of the screen that when the user presses brings them either to the app's GooglePlay page or my GooglePlay profile page (whichever way I decide before hand).
After doing some searching on a guide for doing this I found this link below which basically shows what I want and gives some script for doing it, the problem is I'm not exactly sure which file I need to place this script and where in it exactly, do I put this script somewhere in the AndroidManifest.xml file ? The layout main.xml ?
http://www.appsgeyser.com/blog/tag/customized-code/
Any help would be appreciated I'm new to this Android App stuff.
First, you need to add a Button to your layout which should contain the Button. In your case it's main.xml from the layout folder. Then your main.xml should look similar to this one:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--other Views-->
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:text="My Apps" />
</RelativeLayout>
In your MainActivity you assign an OnClickListener to this Button:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//open up browser or play store with the provided link
String url = linkToYourDeveloperPage;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
}
Inside onClick you create an Intent with an url which shows your developer page or your apps in the Play Store.
If you'd like to have an image rather than just text, you can also use ImageButton.

Removing "Persistent Footer Button" When Keyboard is Called - Material Design

My question is the following, how do I go about removing a RelativeLayout containing buttons every time the user calls up the soft keyboard to type on an editText on the same layout. As you can see on my images below, the buttons within the red box need to disappear every time the user is inputing information and reappear after the keyboard has been called off.
FYI - The RelativeLayout needs to be fixed at the bottom when the keyboard is not in view so "layout_alignParentBottom='false' is not a solution for me. I think this most likely needs to be done programatically.
Any suggestions on how to tackle this problem would be highly appreciated.
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="#dimen/activity_margin_zero"
android:background="#color/background"
android:minHeight="48dp"
android:padding="#dimen/activity_margin_zero">
Here is what Google Android Developer site describes as "Persistent Footer Button"
This is what I have but the so called "Persistent Footer Button" should disappear when the keyboard is on screen.
Buttons should be behind keyboard when it shows or disappear so that the user can input information with more screen real state.
Have you tried modifying the windowSoftInputModeproperty of your activity?
In your manifest, for the related activity, set the property like so:
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustPan"
... >
</activity>
RelativeLayout footer = (RelativeLayout) findViewById(R.id.footer);
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
footer.setVisibility(View.VISIBLE)
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
footer.setVisibility(View.INVISIBLE)
}
}
Note: The above code will only called for virtual keyboard also check out this Listen for keyboard show or hide event in android

Android tab bar with different fragments and different action bar icons

Problem Description and Question
I'm using tab activity with action bar. In the HOME tab I have GridView which contains some items, like it is shown in the image below (Hot Lines, Taxi, Restaurants etc)
Wen user click on the items in the grid view I want my application to take following actions:
Change icon of application to grid view item image on which I pressed.
Change the test near the icon
Add standard back button near icon, which will go back to grid view screen.
Change the tab fragment to the one which I specify.
Like it is shown in the image below:
As I never deal with this kind of problems can you please give me example or share some link with me of how I can do this? and can I do this at all?
This might help:
Android studio - is possible to add tabs pointing to fragments from designer?
It is not exactly what you want, but a good start. If you are willing to put a bit of work in it, you should be able to get what you want. If you have a basic Frame to work with and more specific problems with this matter I will gladly help you out ^^
John
The first link you can check is THIS.
And you should read more about ActionBar.
The last thing is it's better if you google it first and try to write a code and when you got stuck somewhere share your code with us and ask for help.
You have to use actionbarsherlock library for it.
use android.support.v4.app.FragmentTabHost and TabWidget in the xml as shown below :
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
style="#style/yourstyle"/>
<FrameLayout
android:id="#+id/realtabcontent"
style="#style/realtabFrameContentStyle" />
<TabWidget
android:id="#android:id/tabs"
style="#style/yourtabstyle" />
</android.support.v4.app.FragmentTabHost>
Use SherlockFragmentActivity for showing the tabs.
In the activities code use following code (preferably in a function) to set the ctionbar icon and text :
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setCustomView(R.layout.your_action_barlayout);
((TextView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.action_bar_title))).setText("your title");
ImageView homeButton = ((ImageView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.your_icon)));
homeButton.setVisibility(View.VISIBLE);
homeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, YourHOmeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
activity.finish();
}
});
ActionBar mActionBar = activity.getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.show();
then call this function with your icon and your text in your fragments onResume() method.

Categories

Resources