start building app.. and immediately need your help - Android Software Development

Hello.
I'm very new to app developing but for starting learning I'd like to modify an app I have, doing two things:
1) in this app I have an edit text (with the cursor blinking) and a custom keyboard (not the system one, but one just of that app) for writing on it (something like a lockscreen). The problem is that whenever I press the keyboard buttons, despide of seeing my touch on them, nothing appear in the edit text.
Here's the layout.xml
Code:
<com.android.internal.widget.PasswordEntryKeyboardView android:id="@id/keyboard" android:background="#00000000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:keyBackground="@drawable/btn_keyboard_key_fulltrans" />
Is this right?
Where can I find why it's not writing? In the PasswordEntryKeyboardView.smali?
2) I'd like also to have the status bar visible but not expandable. I've found I should do it putting a overlay over status bar and consumed all input events. So I'd need a custom class which extends any layout and consumes touch event and then to consume touch event override the onInterceptTouchEvent method of the view group and return true.
This should be the code for that custom class (customViewGroup):
Code:
WindowManager manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
So, how to do it...
Do I have to add a new .smali in the widget folder with that code or can I add that code in a file there?
And how to override the onInterceptTouchEvent method of the view group and return true?
And how to remove it when I leave that app?
I hope someone helps me learning.
Thanks.

Related

Change battery icon with activity

With my program I launch a activity that show a fake alertdialog for battery low. Now I want change also the icon battery on status bar but this is a system icon and there is not api for to do this. I found on the Internet this not public API http://grepcode.com/file/repository.../com/android/server/status/StatusBarIcon.java but I have a problem for this line :
1) View v = inflater.inflate(com.android.internal.R.layout.status_bar_icon, parent, false);
2) AnimatedImageView im = (AnimatedImageView)v.findViewById(com.android.internal.R.id.image);
because on official API there is not a com.android.internal.R.layout.status_bar_icon or com.android.internal.R.id.image I tried to replace with costant int value but for first line I get View v = [email protected] but for second line I get AnimatedImageView im = null :-(
How can I do it?
I can not do it, I thought of creating a transparent activity in fullscreen modo and notitle and put my fake battery image on the top and with layout margin left put it over the battery icon. I tried it but my image go under the status bar...why ?? :-(

[Q] Making an alternatice UI menu (like for example: the camera menu)

I am trying to create a more appealing menu for my application, however I am unsure as how to re-root the input of the menu button so that it makes certain images in the corners visible, (they are all in the same xml file, however just set to "invisible" by default. If also possible I'd like to activate this menu by just touching the screen, does anyone have any advice on how to do this?
If you need any more information please just ask
Thank you
You'll need to capture the menu button click. This might help:
http://stackoverflow.com/questions/4239880/detecting-physical-menu-key-press-in-android
For touching the screen you'll need an onTouch event for the view.
Sent from my HTC Desire using XDA App
thanks
but i am still unsure as how to identify the xml object and then change it's visibility in java
image:
Code:
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_bottom_left"
android:id="@+id/bl"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:visibility="invisible"></ImageView>
using the physical keycode:
Code:
public boolean onKeyUp(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_MENU)
{
}
return true;
}
sorry but i am not that familiar with java
OK.
// Create an ImageView and assign it to your bl ImageView
Imageview bl= (ImageView)findViewById(R.id.bl);
// Change the visibility (VISIBLE = Visible, INVISIBLE = Invisible but takes up the same space in layout
// GONE = Invisible and does not take up space in layout)
bl.setVisibility(ImageView.VISIBLE);
Hope this helps

[Q] MediaController defined in XML

So I have the following code which works OK:
Code:
VideoView videoView = (VideoView)findViewById(R.id.videoView1);
videoView.setVideoPath("android.resource://" + getPackageName() + "/raw/"+R.raw.intro);
MediaController controller = new MediaController(this);
controller.setAnchorView(videoView);
controller.setPadding(0, 0, 0, 500);
videoView.setMediaController(controller);
videoView.setZOrderOnTop(true);
However, if I test the app on a phone with a smaller screen, the MediaController is positioned like s**t. So I tried to define it in the xml file so it keeps the same postion on different devices
Code:
<MediaController
android:id="@+id/mediaController1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/videoView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" >
</MediaController>
and changed the code to
Code:
VideoView videoView = (VideoView)findViewById(R.id.videoView1);
videoView.setVideoPath("android.resource://" + getPackageName() + "/raw/"+R.raw.intro);
MediaController controller = (MediaController)findViewById(R.id.mediaController1);
videoView.setMediaController(controller);
// controller.setAnchorView(videoView);
videoView.setZOrderOnTop(true);
But now, the app crashes when I start it. Is there something I'm missing here? How can I use the MediaController defined in the XML?
Check this: http://stackoverflow.com/questions/...oid-mediacontroller-to-appear-from-layout-xml
And please post a logcat. Otherwise nobody will be able to help you.
Here's the logcat. I'm just trying to have the mediaController in the position set in the xml, so that it stays relative to any screen sizes
I also tried this, from an answer in that link, but the mediaController just goes to the default position at the bottom of the screen
Code:
VideoView videoView = (VideoView)findViewById(R.id.videoView1);
videoView.setVideoPath("android.resource://" + getPackageName() + "/raw/"+R.raw.intro);
MediaController controller = new MediaController(this);
View controllerView = (View)findViewById(R.id.mediaController1);
controller.setAnchorView(controllerView);
videoView.setMediaController(controller);
videoView.setZOrderOnTop(true);

Show spinner on left when ActionMode is active

I have a gridview supporting multiple selection, when user selects one item the action bar shows the classic AcitonMode and the menu items as defined in layout/menu files, every works fine.
Now I want to add a spinner and show it on the left side (like Gallery does) but defining it on the menu.xml it is positioned near other menu items (on right), so how can I create a spinner on left side and menu items on right side like on Gallery app??
I've searched on Gallery source code but it is really complicated
My current menu definition is show below
Code:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_selection_spinner"
android:actionViewClass="android.widget.Spinner"
android:showAsAction="always"/>
<item
android:id="@+id/action_edit"
android:showAsAction="always"
android:title="@string/edit_title"/>
</menu>
My onPrepareActionMode method
Code:
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
Spinner selectionSpinner = (Spinner) menu.findItem(
R.id.item_selection_spinner).getActionView();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActionBar()
.getThemedContext(), R.layout.path_spinner_dropdown_item);
selectionSpinner.setAdapter(adapter);
adapter.addAll("One item selected", "Select All");
return true;
}
I'm not sure, but I think you have to use a custom layout instead of your menu-xml file.
Regards
EmptinessFiller said:
I'm not sure, but I think you have to use a custom layout instead of your menu-xml file.
Regards
Click to expand...
Click to collapse
Yes, using setCustomView works fine, thanks

[Q] How To: Randomize a list??

Dear Friends,
I'm working on an application which has a list of 5 items connected to a database at the back end. I would like to know how can I randomize the order of appearance of these 5 items in these list every time the app start?
Ex
Item 1: A
Item 2: B
Item 3: C
Item 4: D
Item 5: E
Next time the app launches the order of appearance is at random.
Ex
Item 1: C
Item 2: E
Item 3: A
Item 4: D
Item 5: B
So, on and so forth for every instances of app launch.
Also, how can I add transition animation (fade in, fade out, slide in, etc) like most of the modern web-pages have for the app UI. I do not have much programming experience. Just a learner. All help will be appreciated.
Look on the animations tutorial at androidhive.info ( i think it's proper address ).
Answering the first question, I would write method for database that returns list of items and implement randomization in it. Then just create instance of database in onCreate and make just like this : List<Item> randomList = db.returnRandomList();
I think this would be the easiest and most explanatory way that you could understand for the random list
Code:
private ArrayList<String> random(ArrayList<String> list)
{
ArrayList<String> randomList = new ArrayList<String>();
while(list.size() > 0)
{
int randomInt = new Random(System.currentTimeMillis()).nextInt(list.size());
randomList.add(list.get(randomInt));
list.remove(randomInt);
}
return randomList;
}
So with that imagine doing it with "_id"'s before asking the cursor for rows (though you would need all the primary keys to start with to do that on)... hope that gives you enough to start with
as for anims thats part of the view class and much info on d.android.com
To randomize the list use Java's Collections. Shuffle method and pass in ur list.
In order to display animations, after u call startactivity, make a call to overridependingtransition and pass in animations for the entering and exiting activity.
Sent from my XT1022 using XDA Free mobile app

Categories

Resources