MINI_THUMB_MAGIC usage - android

I wonder if I can use MINI_THUMB_MAGIC from MediaStore.Images.Media to create the Uri for the thumbnails, for example something like below:
"content://media/external/images/thumbnails/" + "kind_mini" +"/"+ thumbId

JAVA
package app.test;
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
public class Test extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imgView = (ImageView) findViewById(R.id.image3);
imgView.setImageURI(Uri.parse("file://mnt/sdcard/d2.jpg"));
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is at /res/layout/list.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="fill_parent">
<ImageView android:id="#+id/image1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/icon"
/>
<ImageView android:id="#+id/image2"
android:layout_width="125dip" android:layout_height="25dip"
android:src="#555555"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="fill_parent">
<ImageView android:id="#+id/image3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
/>
<ImageView android:id="#+id/image4"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/icon"
android:scaleType="centerInside"
android:maxWidth="35dip" android:maxHeight="50dip"
/>
</LinearLayout>
</LinearLayout>

Related

Generating QR Code on different activity in android

i have been trying to create a QR Code generator that generates the QR Code on a separate activity on button click. Below is my code but it crushes on button click. Where did i go wrong?
First class is MainActivity.class:
package com.example.profmox.myapplication;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.journeyapps.barcodescanner.BarcodeEncoder;
public class MainActivity extends AppCompatActivity {
TextView tx1;
Button btn1, btn2;
EditText edt1,edt2;
CheckBox ch;
String text2qr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt1 = (EditText)findViewById(R.id.edit1);
edt2 = (EditText)findViewById(R.id.edit2);
btn1 = (Button)findViewById(R.id.login);
btn2 = (Button)findViewById(R.id.signup);
ch = (CheckBox)findViewById(R.id.check);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.v("EditText", edt1.getText().toString());
Log.v("EditText", edt2.getText().toString());
// text2qr = edt1.getText().toString().trim();
// MultiFormatWriter mfw = new MultiFormatWriter();
// try{
// BitMatrix btm = mfw.encode(text2qr, BarcodeFormat.QR_CODE,250,250);
// BarcodeEncoder ben = new BarcodeEncoder();
// Bitmap bmap = ben.createBitmap(btm);
// UserScreen.qr.setImageBitmap(bmap);
// }catch (WriterException e){
// e.printStackTrace();
// }
startActivity(new Intent(MainActivity.this, UserScreen.class));
}
});
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SignUp.class));
}
});
}
}
The layout file for the MainActivity class:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/art_background"
tools:context="com.example.profmox.myapplication.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="300dp"
android:layout_height="230dp"
android:layout_gravity="center_horizontal"
android:padding="16dp"
android:layout_marginTop="20dp"
android:src="#mipmap/logo"/>
<EditText
android:id="#+id/edit1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textEmailAddress"
android:ems="10"
android:background="#android:color/transparent"
android:drawablePadding="12dp"
android:padding="8dp"
android:hint="Username"
android:textColorHint="#fff"
android:maxLines="1"
android:drawableLeft="#drawable/girl"
android:layout_marginTop="70dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#F2CC8F"/>
<EditText
android:id="#+id/edit2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPassword"
android:ems="10"
android:background="#android:color/transparent"
android:drawablePadding="12dp"
android:padding="8dp"
android:hint="Password"
android:textColorHint="#fff"
android:maxLines="1"
android:layout_marginTop="4dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#F2CC8F"/>
<CheckBox
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#fff"
android:text="Remember Me"
android:padding="9dp"
/>
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/login_art"
android:text="Login"
android:textColor="#3D405B"
android:textAllCaps="false"
android:padding="16dp"
android:clickable="true"
style="#style/Base.TextAppearance.AppCompat.Body1"
android:layout_marginTop="23dp"
android:textSize="18sp"/>
<Button
android:id="#+id/signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/signuo_art"
android:text="Sign up"
android:textColor="#fff"
style="#style/Base.TextAppearance.AppCompat.Body1"
android:textAllCaps="false"
android:textSize="18sp"
android:layout_marginTop="16dp"
android:clickable="true"
android:padding="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot your password?"
android:clickable="true"
style="#style/Base.TextAppearance.AppCompat.Body2"
android:padding="16dp"
android:layout_marginBottom="12dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
The UserScreen.class is where i want to generate the QR Code in:
package com.example.profmox.myapplication;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
public class UserScreen extends AppCompatActivity {
static ImageView qr;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_screen);
qr = (ImageView)findViewById(R.id.qrCode);
}
}
The layout file for the UserScreen.class:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/art_background"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.profmox.myapplication.UserScreen">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/qrCode"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

How to make Ads to load in Background because now lags

I'm making a GymExercises app. I have two questions:
I include ads in every Exercise but now the UI lags too much. How can I put them in the background so they run in the background?
When I use smart banner, sometimes it doesn't show ads. With small banner, it's working perfectly.
BenchFragment.java:
package com.Hristijan.Aleksandar.GymAssistant.Exercises;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class BenchFragment extends Fragment {
private VideoView player;
private String videopath;
private MediaController mediacon;
public View rootView;
private AdView mAdView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_bench, container, false);
mAdView = rootView.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
MobileAds.initialize(getActivity().getApplicationContext(), "ca-app-pub-7751214307362146~7028081975");
mAdView.loadAd(adRequest);
mediacon = new MediaController(getActivity());
player = (VideoView) rootView.findViewById(R.id.videoplayer);
videopath = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.bench;
player.setVideoURI(Uri.parse(videopath));
mediacon.setAnchorView(player);
player.start();
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.setVolume(0, 0);
}
});
return rootView;
}
}
fragment_bench.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/bench_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:fillViewport="true"
tools:context="com.Hristijan.Aleksandar.GymAssistant.Exercises.BenchFragment">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:layout_width="match_parent"
android:layout_height="#dimen/_160sdp"
android:foregroundGravity="center"
android:id="#+id/videoplayer" />
<TableLayout
android:layout_below="#+id/videoplayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*">
<TableRow>
<TextView
android:text="#string/group"
android:background="#color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#ffffff"
android:textSize="#dimen/_10sdp"
android:padding="5dip" />
</TableRow>
<TableRow>
<TextView
android:text="#string/bencbody"
android:textSize="#dimen/_10sdp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#ffffff"
android:padding="5dip" />
</TableRow>
<TableRow>
<TextView
android:text="#string/description"
android:textSize="#dimen/_10sdp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:textColor="#ffffff"
android:padding="5dip" />
</TableRow>
<TableRow>
<TextView
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:layout_marginTop="5dp"
android:text="#string/stepone"
android:textColor="#android:color/white"
android:textSize="#dimen/_10sdp"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:gravity="left"
android:text="#string/steptwo"
android:textColor="#android:color/white"
android:textSize="#dimen/_10sdp"
android:padding="3dip" />
</TableRow>
</TableLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-7751214307362146/9071791385">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</ScrollView>

Casting to checkbox from android.view

I`ve been trying to build my app in android studio workbench, however I have stumbled across an error message reading "cannot cast from view to checkbox". I have tried different things to resolve the issue to no avail.
This is mainactivity code:
package com.example.sonu.animal;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
public class MainActivity extends AppCompatActivity {
private Checkbox check1,check2,check3;
private Button b1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addListnerOnButton() {
check1 = (Checkbox)findViewById(R.id.checkBox_dog);
check2 =(Checkbox)findViewById(R.id.checkBox2);
check3= (Checkbox)findViewById(R.id.checkBox3);
b1 = (Button)findViewById(R.id.button);
}
}
This is xml file:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.sonu.animal.MainActivity">
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="dog"
android:id="#+id/checkBox_dog"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:checked="false" />
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cat"
android:id="#+id/checkBox2"
android:layout_below="#+id/checkBox_dog"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp"
android:hint="cat"
android:checked="false" />
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cow"
android:id="#+id/checkBox3"
android:layout_below="#+id/checkBox2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="40dp"
android:checked="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="select"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

Not-clipped childview of RelativeLayout is not clickable

I have the following activity. It is an simplification of a draggable map. The problem is that mytext2 is not clickable, even if it is visible. Can anybody tell me how to make it clickable? And for some reason the inner-RelativeLayout gets not bigger than screen size, even when i set this high dp.
<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"
android:background="#0000ff"
android:clipChildren="false"
tools:context="${relativePackage}.${activityClass}" >
<RelativeLayout
android:layout_width="100000dp"
android:layout_height="100000dp"
android:background="#00ff00"
android:translationX="-100dp" >
<TextView
android:id="#+id/mytext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:translationX="400dp"
android:translationY="100dp" />
<TextView
android:id="#+id/mytext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:translationX="200dp"
android:translationY="100dp" />
</RelativeLayout>
</RelativeLayout>
class
package com.example.relativatest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.mytext1).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("HELLO!1");
}
});
findViewById(R.id.mytext2).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("HELLO!2");
}
});
}
}
Use this code.
<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"
android:background="#0000ff"
android:clipChildren="false"
tools:context="${relativePackage}.${activityClass}" >
<RelativeLayout
android:layout_width="100000dp"
android:layout_height="100000dp"
android:background="#00ff00"
android:translationX="-100dp" >
<TextView
android:id="#+id/mytext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:focusable="true"
android:padding="20dp"
android:translationX="400dp"
android:clickable="true"
android:translationY="100dp" />
<TextView
android:id="#+id/mytext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:translationX="200dp"
android:clickable="true"
android:padding="20dp"
android:focusable="true"
android:translationY="100dp" />
</RelativeLayout>
</RelativeLayout>

android tabwidget need help

Hello all this is my code for the tab layout in to android i want them in to bottom of the scrren currently it shows me at top of the screen
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentBottom="true"
android:gravity="bottom">
<TabHost android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<HorizontalScrollView android:scrollbars="none"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="#android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
tab.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#drawable/tab_background_selector" android:gravity="center"
android:orientation="vertical" android:padding="5dp"
android:layout_alignParentBottom="true" >
<ImageView android:id="#+id/tab_icon" android:layout_width="30dp"
android:layout_height="30dp" android:scaleType="fitCenter" />
<TextView android:id="#+id/tab_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:singleLine="true"
android:textStyle="bold" android:gravity="center_horizontal"
android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee"
android:textColor="#drawable/tab_text_selector"
android:layout_alignParentBottom="true" />
</LinearLayout>
this is my activity class
TestActivity.java
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
public class TestActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maiin);
final TabHost tabHost = (TabHost) getTabHost();
tabHost.addTab(createTab(MobiintheMorningActivity.class,
"Welcome", "Welcome", R.drawable.icon));
tabHost.setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
}
private TabSpec createTab(final Class<?> intentClass, final String tag,
final String title, final int drawable)
{
final Intent intent = new Intent().setClass(this, intentClass);
final View tab = LayoutInflater.from(getTabHost().getContext()).
inflate(R.layout.tab, null);
((TextView)tab.findViewById(R.id.tab_text)).setText(title);
((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);
return getTabHost().newTabSpec(tag).setIndicator(tab).setContent(intent);
}
}
here i've used android:layout_alignParentBottom="true" but no effects at all what should i do? what thing i am missing? thanks in advance :Pragna
See the solution to put the tab bar at the bottom.
Change the position of FrameLayout and widget in your xml.I think that my help you

Categories

Resources