Question regarding ImageView cropping / sizing and alignment in app widgets - Android Q&A, Help & Troubleshooting

Hi developers,
I have a special problem and didn't find a solution for it yet. So I hope that anybody here had a similar issue and can point me to a solution.
The problem:
Basically I use an ImageView inside my widgets. When the image is smaller than the ImageViews space then there is no problem.
The problem raises when the image gets bigger than the ImageView.
In some cases I want that the image doesn't get scaled but cropped and then aligned due to the users option.
What I want to achive is that the ImageView gets as big as the image and then is aligned (top, right, bottom, left). The rest of the image should get clipped by the container.
All I could achive until now is that the image gets cropped and centerd (all done by the ImageView).
Here is the xml I use for the widgets:
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/widgetbackground"
android:focusable="true" >
<!-- [...] -->
<LinearLayout
android:id="@+id/llTextBlock"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/llText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/llContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- [...] -->
<ImageView
android:id="@+id/imgContentDontScale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/widgetbackground"
android:focusable="true"
android:scaleType="center"
android:visibility="gone" >
</ImageView>
</LinearLayout>
<!-- [...] -->
</LinearLayout>
</LinearLayout>
<!-- [...] -->
</RelativeLayout>
The ImageView in question is the "imgContentDontScale" one.
The solution has to work on widgets (so almost only xml defined excluding the "RemotableViewMethod" marked methods) and ist has to be Froyo compatible.
Thanks
Michael

Related

[Q] Removing Overlay Text on Battery Mod

Hello all,
I have submitted and successfully updated my device (Archos43) with the Crysis Battery Mod and it works like a champ. The problem is that the original archos battery icon has a text overlay of the battery capacity (0-100). This doesn't work with the mod, because the mod has the capacity in the img.
I have looked into the extracted framework-res.apk's \res\layout\battery_status.xml and have modified the two TextViews to have an alpha of 00, but that didn't work either.
I was curious if anyone has experience with this and could point me in the right direction.
(I think this is the proper place for this post..)
Thanks!
RJV
(battery_status.xml)
Code:
(battery_status.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center_horizontal" android:orientation="vertical" android:id="@id/frame" android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="*Removed, less than 8 posts!*">
<FrameLayout android:background="@drawable/battery_charge_background" android:paddingLeft="1.0px" android:paddingTop="25.0px" android:layout_width="141.0px" android:layout_height="184.0px">
<LinearLayout android:orientation="vertical" android:id="@id/meter" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_width="fill_parent" android:layout_height="15.0dip" />
<ImageView android:id="@id/spacer" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="@id/level" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<TextView android:textSize="48.0dip" android:textStyle="bold" android:textColor="#ffffff00" android:gravity="center" android:id="@id/level_percent" android:layout_width="fill_parent" android:layout_height="fill_parent" />
</FrameLayout>
<TextView android:textSize="30.0dip" android:textStyle="bold" android:textColor="#ffffff00" android:gravity="center_horizontal" android:id="@id/status" android:paddingTop="35.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/battery_status_charging" android:singleLine="true" />
</LinearLayout>
Please use the Q&A Forum for questions Thanks
Moving to Q&A
Bump.
Also some updated information. It appears that looking at the framework-res.apk was the incorrect place to look. It now seems like I have to work with the services.jar. I have narrowed it down to updateBattery() function within StatusBarPolicy.smali. Does anyone have any information that would lead me in the right direction?
Thanks!

[Q] Need Help with an application and coding

I have created a new xml file in the res>layout forlder called tabs.xml. It has the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="vertical" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/Network"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Channel Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="@+id/urbanButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:text="Urban" />
<RadioButton
android:id="@+id/suburbanButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/urbanButton1"
android:layout_alignBottom="@+id/urbanButton1"
android:layout_centerHorizontal="true"
android:text="SubUrban" />
<RadioButton
android:id="@+id/ruralButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/suburbanButton2"
android:layout_alignBottom="@+id/suburbanButton2"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:text="Rural" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/urbanButton1"
android:text="Characteristics of Channel:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/suburbanButton2"
android:layout_below="@+id/textView2"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_toLeftOf="@+id/ruralButton3"
android:text="Manual Override" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/power"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/Connectivity"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/Offline"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
</FrameLayout>
</LinearLayout>`enter code here`
</TabHost>
</LinearLayout>
Now i also have a andoid activity_main.xml in the same folder which i added nothing to it. i also created a java file called Tabs.Java and put it in the src folder under src>com.example.qosmetre>Tabs.Java with the following code
package com.example.qosmetre;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Tabs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
}
}
Now my question is, when i run my app on the terminal or in debugging mode, how come nothing is showing up but a blank screen? Like i want the tabs to show up first thing with all the stuff underneath them as shown in the code above. Also how would i import a library for scatter plotting data that would be in my app?
I need to know where and what files to put what code in because im just a beginner and i dont know too much so ill need big guidence.
Thanks again in advance.

[Q] Android GestureOverlayView Drawerlayout xml

How can I use my gesture overlay view with navigation drawer? I'm adding the navigation drawer to the app with gesture overlay already working. I want to just add the swipe menu and if i have to give up the swipe gesture for the just have the action bar push button is fine. I just can't figure how to combine? I get an error before the app can start saying the it can't inflate class Drawer layout. See my XML code under.
Code:
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gestureOverlayView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#666"
android:dividerHeight="1dp"
android:background="#333"
android:paddingLeft="15sp"
android:paddingRight="15sp"
/>
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/timerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="5sp"
android:text="@string/startTime"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="30sp" />
<TextView
android:id="@+id/instructionTextView"
android:layout_width="574dp"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:textSize="40sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</android.gesture.GestureOverlayView>

[Q] Changing a string item into a drawable?

Okay, so I'm using Android 4.3 on Xperia M, and the dialpad numbers are strings (their font change with the system's font). I want to make it drawables so that I can theme the dialpad using my own icons. Is this possible, and if it is, how should I do it? Should I edit one of the xmls after decompiling it?
The framework and the dialer/contacts apk:
https://drive.google.com/file/d/0B956mjWProLXRy0xUkJhYlhTTW8/edit?usp=sharing
https://drive.google.com/file/d/0B956mjWProLXY0xoRFAtM1JVQVU/edit?usp=sharing
https://drive.google.com/file/d/0B956mjWProLXQWd2ME1fczNTNUk/edit?usp=sharing
GeniuSotaKu said:
Okay, so I'm using Android 4.3 on Xperia M, and the dialpad numbers are strings (their font change with the system's font). I want to make it drawables so that I can theme the dialpad using my own icons. Is this possible, and if it is, how should I do it? Should I edit one of the xmls after decompiling it?
The framework and the dialer/contacts apk:
https://drive.google.com/file/d/0B956mjWProLXRy0xUkJhYlhTTW8/edit?usp=sharing
https://drive.google.com/file/d/0B956mjWProLXY0xoRFAtM1JVQVU/edit?usp=sharing
https://drive.google.com/file/d/0B956mjWProLXQWd2ME1fczNTNUk/edit?usp=sharing
Click to expand...
Click to collapse
Change @string to @drawable should work and place the pngs
SpinXO said:
Change @string to @drawable should work and place the pngs
Click to expand...
Click to collapse
Thanks.
I want to ask another thing, if it's fine with you.
EDIT: App force close after a few seconds after recompile, and the dialpad remains the same. Tell me where I went wrong. The "nothinghere" is a transparent image.
HTML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:id="@id/dialpad" android:layout_width="fill_parent" android:layout_height="fill_parent" android:baselineAligned="false"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ex="http://schemas.android.com/apk/res/com.sonyericsson.android.socialphonebook">
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="0.0dip" android:baselineAligned="false" android:layout_weight="15.0" android:layoutDirection="ltr">
<com.sonyericsson.android.socialphonebook.ui.widget.DialpadButtonView android:id="@id/one" android:focusable="true" android:clickable="true" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0" android:soundEffectsEnabled="false" android:layoutDirection="ltr" android:paddingStart="@dimen/dialpad_button_padding_left" ex:normalBackground="@drawable/dial_num" ex:pressedBackground="@drawable/dial_num_pressed">
<TextView android:id="@id/oneNum" android:layout_width="@dimen/dialpad_button_num_text_width" android:layout_height="wrap_content" android:text="@string/lockscreen_strings_dialpad_1_txt" android:contentDescription="@string/spb_accessibility_one_and_voicemail_txt" style="@style/Dialpad.Digit" />
<LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:baselineAligned="false" android:layout_centerVertical="true" android:layout_toEndOf="@id/oneNum">
<TextView android:id="@id/oneSearchLabel" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/nothinghere" android:layout_marginStart="@dimen/dialpad_search_lable_margin_left" style="@style/Dialpad.Label" />
<ImageView android:id="@id/voicemail_icon" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dialpad_1" />

Deformin self images for ToggleButton

Hi dear developers,
I spend much time with this issue.
When I create LinearLayout with four ToggleButtons with self images, button image will not keep aspect ratio, images will be deformed.
Button images pressed in vertical, not in horizontal.
This is layout code with deformed images:
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0px"
androidrientation="horizontal">
<ToggleButton
android:id="@+id/bt1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/led"
android:text="Led"
android:textOff="BT1"
android:textOn="BT1" />
<ToggleButton
android:id="@+id/bt2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/led"
android:text="Led"
android:textOff="BT2"
android:textOn="BT2" />
<ToggleButton
android:id="@+id/bt3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/led"
android:text="Led"
android:textOff="BT3"
android:textOn="BT3" />
<ToggleButton
android:id="@+id/bt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/led"
android:text="Led"
android:textOff="BT4"
android:textOn="BT4" />
</LinearLayout>
When I create similar LinearLayout with four ImageViews instead of ToggleButtons with same images, images not will be deformed. Same images keep aspect ratio. Button images pressed in vertical and horizontal with same ratio.
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0px"
androidrientation="horizontal">
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/led" />
<ImageView
android:id="@+id/img2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/led" />
<ImageView
android:id="@+id/img3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/led" />
<ImageView
android:id="@+id/img4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/led" />
</LinearLayout>
I don't know, why it's behavior different. Size of image is 128 x 128 pixels in png file.
How I can reach that ToggleButton's image will keep aspect ratio for all relative sizes?
Application is compiled in Android Studio 3.6.1 with build gradle:
...
android {
compileSdkVersion 25
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.nabto.androidaudiodemo"
minSdkVersion 11
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...
Thank you for your help
Srapur

Categories

Resources