Android get captured image meta data - java

I am trying to capture the latitude of an image that has been captured through the camera and stored into the ImageBox variable. Using the ExifInterface class, I am trying to get the latitude of the image and display that information into the LatitudeBox variable but my syntax is incorrect so please let me know what I am doing wrong! full Code below
MainActivity.java
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.ExifInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class MainActivity extends Activity {
//variables
Button CameraButton;
ImageView ImageBox;
EditText LatitudeBox, LongitudeBox;
String IMG = ImageBox.toString();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CameraButton = (Button) findViewById(R.id.CameraButton);
ImageBox = (ImageView) findViewById(R.id.imageView1);
LatitudeBox = (EditText) findViewById(R.id.LatitudeBox);
LongitudeBox = (EditText) findViewById(R.id.LongitudeBox);
//Camera Button Onclick
CameraButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
try {
ExifInterface exif = new ExifInterface(IMG);
LongitudeBox.setText(exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF)); // get longitude
LatitudeBox.setText(exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF)); //get latitude
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// try catch
}// end onclick
});// end camera button onclick
}// close oncreate
//display image inside ImageBox variable using bitmap
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 0)
{
Bitmap TheImage = (Bitmap) data.getExtras().get("data");
ImageBox.setImageBitmap(TheImage);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}// close main
App now crashes on launch and not sure what's causing it. Here is an image of the logcat errors
http://s7.postimg.org/4p67papyj/logcat1.png
activity_main.XML
<ImageView
android:id="#+id/imageView1"
android:layout_width="250dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/CameraButton"
android:layout_width="150dp"
android:layout_height="35dp"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:text="#string/Camera_Button" />
<TextView
android:id="#+id/LatitudeBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/CameraButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="#string/LatitudeBox"
android:textColor="#ff0000"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/LongitudeBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LatitudeBox"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp"
android:text="#string/LongitudeBox"
android:textAppearance="?android:attr/textAppearanceLarge" />

There is no .get() method for ExifInterface.
LatitudeBox = exif.get(ExifInterface.TAG_GPS_LONGITUDE_REF);
Did you perhaps mean:
LatitudeBox.setText(exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF));
EDIT:
I found it.
Look at the last variable here:
Button CameraButton;
ImageView ImageBox;
EditText LatitudeBox, LongitudeBox;
String IMG = ImageBox.toString();
You haven't assigned a value to your ImageView ImageBox. So when you ImageBox.toString(), you receive a NullPointerException.
Change initialization of IMG to something like:
String IMG = "filename.txt";

Related

Move Image Left & Right When it Zoomed

How to move image right to left when it zoomed ? I have done zooming on images and now don't know which codes to write for creating movement using finger once it zoomed.
Please have a look at my code and give me your precious reply. Edit my code if possible. Thanks in advance.
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ZoomControls;
public class MainActivity extends Activity {
ImageView img;
ZoomControls zoom;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.imageView1);
zoom = (ZoomControls) findViewById(R.id.zoomControls1);
zoom.setOnZoomInClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int w = img.getWidth();
int h = img.getHeight();
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(w + 10, h +10);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
img.setLayoutParams(params);
}
});
zoom.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int w = img.getWidth();
int h = img.getHeight();
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(w - 10, h -10);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
img.setLayoutParams(params);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml
<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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher" />
<ZoomControls
android:id="#+id/zoomControls1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp" />
Try this library..it easy to implement and works flawlessly
Image Zoom Library

Populating Listview from database when item selected in a spinner then button clicked

Ok, so I'm creating an application that will use current gps location (lat/long). The user will have to select a specified radius (.5-100 miles) from a Spinner. Then, when clicked, there will be a Button (onClickListener()) that will populate the locations from a SQLite database, in that set radius, to a ListView. From there, select an item from the ListView that will call an Activity (Intent).
I have the ListView populating data from the database, but I'm having issues with it populating from an onClick event (Button). Furthermore, if anyone can figure out how to get the current location to compare the locations listed in the database based on the set radius (from the Spinner), and show the ones that match in the ListView, I would REALLY appreciate that.
Thanks!
SN: I have it displaying the current location. Here's my code.
Java file
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class MetersActivity extends ActionBarActivity {
private Toolbar toolbar;
private DrawerLayout drawerLayout;
private static Button search;
private TextView myAddress;
GPSTracker gps;
//new instance of db from meter info database
MeterInfoDatabase myDb;
private Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
final MeterInfoDatabase db = new MeterInfoDatabase(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_meters);
//myDb = new MeterInfoDatabase(this);
final ListView listView = (ListView) findViewById(R.id.MeterList);
Log.d("LOG", "Before testing the database");
/*
Testing Database Part
*/
List<MeterInfoSQL> allMeters = db.getAllMeters();
ArrayList<String> ar = new ArrayList<String>();
for(MeterInfoSQL m : allMeters)
{
//Toast.makeText(getApplicationContext(), m.getMeterNumber() + " Saved", Toast.LENGTH_LONG).show();
String str = "Meter #: " + m.getMeterNumber();
ar.add(str);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ar);
listView.setAdapter(adapter);
toolbar= (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
myAddress = (TextView) findViewById(R.id.myaddress);
//search button click
onClickButtonListener();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_meters, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
//Used to get location via GPS when search button is tapped
public void onClickButtonListener() {
final Context context = this;
search = (Button) findViewById(R.id.MeterSearch_button);
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
gps = new GPSTracker(MetersActivity.this);
//gps coordinates
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
if (gps.canGetLocation()) {
//Shows address
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Your Current Address:\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
myAddress.setText(strReturnedAddress.toString());
} else{
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
}
else {
gps.showSettingsAlert();
}
//want the lisview to populate when this button is clicked
/*when i move it here I get an error at "this"
ArrayAdapter<String> adapter = new ArrayAdapter<String>
//---> here (this, android.R.layout.simple_list_item_1, ar);
listView.setAdapter(adapter); */
}
});
}
}
The XML Layout
<android.support.v4.widget.DrawerLayout 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="#color/background"
tools:context="com.example.ataccofficial.MetersActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff8a8a90"
android:clickable="true"
tools:context="com.example.themetest.MetersActivity">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar" />
<TextView
android:id="#+id/meterSelectRadiusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/app_bar"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:inputType="none"
android:text="Select Radius:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffffff"
android:textSize="25dp" />
<Spinner
android:id="#+id/meter_spinner"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView"
android:layout_below="#+id/meterSelectRadiusText"
android:layout_marginRight="10dp"
android:entries="#array/meter_array"
android:gravity="center"
android:spinnerMode="dialog"
android:textColor="#ffffffff" />
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/meter_spinner"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="27dp"
android:background="#ff8a8a90"
android:text="Location:"
android:textColor="#ffffffff"
android:textSize="15sp" />
<TextView
android:id="#+id/myaddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:autoText="false"
android:editable="false"
android:enabled="false"
android:focusable="true"
android:textColor="#color/primaryColor"
android:textSize="15sp" />
<Button
android:id="#+id/MeterSearch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="Search"
android:text="Search"
android:textSize="25dp"
android:typeface="normal"
android:textStyle="bold"
android:layout_below="#+id/myaddress"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Customer"
android:id="#+id/lablecrm"
android:layout_alignBottom="#+id/dailyReportDivider"
android:layout_alignParentStart="true"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Issue"
android:id="#+id/lableIssue"
android:layout_alignBottom="#+id/dailyReportDivider"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance"
android:id="#+id/lableDistance"
android:layout_alignBottom="#+id/dailyReportDivider"
android:layout_alignParentEnd="true"
android:textColor="#ffffffff" />
<View
android:id="#+id/dailyReportDivider"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/myaddress"
android:layout_alignParentStart="true"
android:layout_marginTop="84dp" />
<ListView
android:id="#+id/MeterList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/dailyReportDivider"
android:layout_centerHorizontal="true"
android:choiceMode="singleChoice"
android:textColor="#ffffffff"/>
</RelativeLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.example.ataccofficial.NavigationDrawerFragment"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
String for Spinner
<string-array name="meter_array">
<item>.5 Miles</item>
<item>1 Miles</item>
<item>5 Miles</item>
<item>10 Miles</item>
<item>15 Miles</item>
<item>20 Miles</item>
<item>25 Miles</item>
<item>50 Miles</item>
<item>100 Miles</item>
</string-array>
Created a method outside of the button listener for populating the listview and called it inside of the listener.
//Used to get location via GPS when search button is tapped
public void onClickButtonListener() {
final Context context = this;
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
gps = new GPSTracker(MetersActivity.this);
//gps coordinates
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
if (gps.canGetLocation()) {
//Shows address
try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Your Current Address:\n");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
myAddress.setText(strReturnedAddress.toString());
} else {
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
} else {
gps.showSettingsAlert();
}
process_data();
}
});
}
private void process_data(){
List<MeterInfoSQL> allMeters = db.getAllMeters();
ar = new ArrayList<String>();
for(MeterInfoSQL m : allMeters)
{
//Toast.makeText(getApplicationContext(), m.getMeterNumber() + " Saved", Toast.LENGTH_LONG).show();
String str = "Meter #: " + m.getMeterNumber() + " Contact " + m.getAccountNumber();
ar.add(str);
}
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ar);
listView.setAdapter(adapter);
doPopulate();
}
private void doPopulate() {
adapter.notifyDataSetChanged();
}
Create another method to handle your task. Inside your onClick() the this statement doesn't refer to the Activity, that's why it's throwing an error.
First of all, try to declare your ArrayAdapter, your ListView and your ArrayList<String> as globals. That can make your work easier to do.
private ArrayAdapter <String> adapter;
private ListView listView;
private ArrayList<String> ar = new ArrayList<String>();
Then, on your onCreate() method change the lines
final ListView listView = (ListView) findViewById(R.id.MeterList);
// ...
ArrayList<String> ar = new ArrayList<String>();
// ...
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ar);
to
listView = (ListView) findViewById(R.id.MeterList);
// ...
ar = new ArrayList<String>();
// ...
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, ar);
Later on your onClickListener().
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// Your code.
// Change your "ar" Array here, and later call the following method.
doPopulate();
}});
private void doPopulate() {
adapter.notifyDataSetChanged();
}
I guess you could simply call the notifyDataSetChanged() from within the onClick(), but I coudn't test this code now. Tell me later if it worked.
You can read more about this here.

instructions for Facebook Like- Button

I have the following problem. I am trying to create a like button for my facebook page, but I got stuck. I followed the instructions but it's not working! I did nowhere see a value to set the coordinates of this button. Where is it? thanks
EDIT2: I edited it again, now, the first onActivityResult has this problem:
void is an invalid type for the variable onActivityresult
what is wrong?
main activity:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import ch.OptiLab.visuscontroll.R;
import com.facebook.UiLifecycleHelper;
import com.facebook.widget.LikeView;
public class MainActivity extends Activity implements OnClickListener {
//UiLifecycleHelper uiHelper;
TextView textView;
// Button buttonende;
Button tipps;
Button btn1;
Button rate;
LikeView LikeView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
tipps = (Button) findViewById(R.id.tipps);
btn1 = (Button) findViewById(R.id.buttonSTART);
btn1.setOnClickListener(this);
rate = (Button) findViewById(R.id.rate);
rate.setOnClickListener(this);
AppRater.app_launched(this);
Settings.sdkInitialize(this);
LikeView = (LikeView) findViewById(R.id.LikeView);
LikeView.setObjectId("http://shareitexampleapp.parseapp.com/photo1/");
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
likeView.handleOnActivityResult(this, requestCode, resultCode, data);
}
tipps.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(R.string.dialog_message)
.setTitle(R.string.dialog_title);
// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
protected Context getActivity() {
return null;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
Toast.makeText(getApplicationContext(), "Easteregg lololol", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onClick(View v) {
startActivityForResult(new Intent(this,VisusActivity.class), 0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == R.drawable.v1)textView.setText(getResources().getString(R.string.nopercent));
else if (resultCode == R.drawable.v2)textView.setText(getResources().getString(R.string.tenpercent));
else if (resultCode == R.drawable.v3)textView.setText(getResources().getString(R.string.twentypercent));
else if (resultCode == R.drawable.v4)textView.setText(getResources().getString(R.string.thirtypercent));
else if (resultCode == R.drawable.v5)textView.setText(getResources().getString(R.string.fourtypercent));
else if (resultCode == R.drawable.v6)textView.setText(getResources().getString(R.string.fiftypercent));
else if (resultCode == R.drawable.v7)textView.setText(getResources().getString(R.string.sixtypercent));
else if (resultCode == R.drawable.v8)textView.setText(getResources().getString(R.string.seventypercent));
else if (resultCode == R.drawable.v9)textView.setText(getResources().getString(R.string.eightypercent));
else if (resultCode == R.drawable.v10)textView.setText(getResources().getString(R.string.ninetypercent));
else if (resultCode == R.drawable.v11)textView.setText(getResources().getString(R.string.onehundretpercent));
}
#Override
protected void onResume() {
super.onResume();
// Logs 'install' and 'app activate' App Events.
}
xml:
<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="ch.OptiLab.visustest.MainActivity" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:gravity="center_horizontal"
android:singleLine="false"
android:text="#string/Text1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/buttonSTART"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="#string/button1"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="142dp" />
<Button
android:id="#+id/buttonende"
android:layout_width="180dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/textView"
android:layout_marginBottom="14dp"
android:text="#string/beenden" />
<Button
android:id="#+id/tipps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonSTART"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:text="#string/tipps_tricks" />
<com.facebook.widget.LikeView
android:id="#+id/LikeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tipps"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp" >
</RelativeLayout>
void is an invalid type for the variable onActivityresult occure because you are using onActivityresult method inside onCreate method. remove this method from onCreate and call
likeView.handleOnActivityResult(this, requestCode, resultCode, data);
from your onActivityResult method. Also check your LikeView variable name it should be same everywhere you are using.
I ran into issues implementing LikeView until I upgraded the Facebook API from 3.18 to 3.20.
Also, you can't use a regular button. You need to use the Facebook LikeView widget like this:
<com.facebook.widget.LikeView
android:id="#+id/lvLike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

How to load Myanmar Language in Web View in android?

I have a web view in which i will enter the URL and load that content to that web view.
activity_main.xml
<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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:visibility="gone" />
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/urlField"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:ems="10"
android:inputType="textUri"
android:imeOptions="actionDone"
android:hint="http://proteam.in" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#+id/layout"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:onClick="open"
android:text="#string/browse" />
</LinearLayout>
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignParentBottom="true"
android:layout_below="#+id/layout" />
</RelativeLayout>
MainActivity.java
package com.example.mayanmarbroswer;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText field;
private WebView browser;
private ProgressDialog pDialog;
final Context context = this;
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
field = (EditText)findViewById(R.id.urlField);
browser = (WebView)findViewById(R.id.webView1);
browser.setWebViewClient(new MyBrowser());
//myTextView.setTypeface(typeFace);
WebSettings webSettings = browser.getSettings();
webSettings.setDefaultTextEncodingName("utf-8");
webSettings.setFixedFontFamily("file:///android_asset/font/Sanpya.ttf");
ActionBar bar = getActionBar();
bar.hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
field.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_DONE)
{
if(field.getText().toString().trim().equals(""))
{
Toast.makeText(getApplicationContext(), "Enter Valid WebSite", Toast.LENGTH_SHORT).show();
}
else
{
open(v);
}
}
return false;
}
});
}
public void open(View view){
String url;
if(field.getText().toString().trim().equals(""))
{
Toast.makeText(getApplicationContext(), "Enter Valid WebSite", Toast.LENGTH_SHORT).show();
}
else
{
if(field.getText().toString().startsWith("http://"))
{
url = field.getText().toString();
}
else
{
url = "http://" + field.getText().toString();
}
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl(url);
}
}
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
/*pDialog = new ProgressDialog(context, ProgressDialog.THEME_HOLO_DARK);
// set indeterminate style
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// set title and message
//pDialog.setTitle("Please wait");
pDialog.setMessage("Loading Pls Wait");
// and show it
pDialog.show();*/
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//do what you want to do
/*if (pDialog.isShowing())
{
pDialog.dismiss();
}*/
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
URL 1: http://www.mora.gov.mm/
URL 2: http://www.saikwan.info/
i tested this in few android device like moto e (4.4.2), Dell venue 7 (4.4.2), Samsung Duos GT-s7392 (4.1.2) and Videocon z40pro(4.2.2) the above given URL with myanmar font is working correctly. but when i try to load that in Samsung GT-s7582(4.2.2) the myanmar fonts are missing in web view. so, please let me know how to solve this issue.
If you fetch data from resource folder i mean asset folder then try this way.
Java Code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonPlayVideo = (Button)findViewById(R.id.playvideoplayer);
Button buttonPlayVideo1 = (Button)findViewById(R.id.button1);
Button acceess = (Button)findViewById(R.id.button2);
getWindow().setFormat(PixelFormat.UNKNOWN);
//Displays a video file.
buttonPlayVideo1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// VideoView refference see main.xml
VideoView mVideoView = (VideoView)findViewById(R.id.videoview);
//String uriPath = "android.resource://com.android.AndroidVideoPlayer/"+R.raw.k;
String uriPath = "android.resource://com.android.AndroidVideoPlayer/"+R.raw.demo;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
}
});
If you fetch from URL or FTP Server OR HTTP Connection then try this way
Java Page
buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//VideoView mVideoView = (VideoView)findViewById(R.id.videoview);
Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Uri.parse("http://192.168.0.8/aeon/")); // For Video Content
// new Intent(Intent.ACTION_VIEW, Uri.parse("ftp://movies:movies#192.168.0.8/Transport_Streams/"));
startActivity(browserIntent);
}});
acceess.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(AndroidVideoPlayer.this,Videopage.class);
startActivity(i);
}
});
}
XML Code Of Both Way are is Given Following way
XML Page for when fetch from the resource
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF8800"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Welcome To Aeon Group"
android:textColor="#9933CC"
android:textSize="3mm" />
<VideoView
android:id="#+id/videoview"
android:layout_width="fill_parent"
android:layout_height="394dp"
android:layout_above="#+id/playvideoplayer"
android:layout_alignParentLeft="true" />
<Button
android:id="#+id/playvideoplayer"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="22dp"
android:background="#drawable/button"
android:text="Aeon Content" />
<!-- <VideoView
android:id="#+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/playvideoplayer"
android:layout_below="#+id/textView1" />
-->
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/playvideoplayer"
android:layout_alignBottom="#+id/playvideoplayer"
android:layout_alignParentLeft="true"
android:background="#drawable/button"
android:text="Play" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/playvideoplayer"
android:layout_alignBottom="#+id/playvideoplayer"
android:layout_toRightOf="#+id/playvideoplayer"
android:background="#drawable/button"
android:text="Acces" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

Can't get text from editText Android

I'm having some issues with my school project. I can't get the text from the textbox. I searched for a solution but nothing found.. I'll be grateful if somebody help me :)
So here is my Java code:
package com.src.vicnote;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.os.Build;
public class NewNoteActivity extends ActionBarActivity {
Button saveButton;
EditText textData;
Context context;
String text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_note);
saveButton = (Button) this.findViewById(R.id.buttonSave);
saveButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
textData = (EditText) findViewById(R.id.editText);
text = textData.getText().toString();
//text = "this is sparta!";
Log.d("ADebugTag", "string: \"" + text + "\" end of note text");
new SaveClass(text/*, context.getApplicationContext()*/);
}
});
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.new_note, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_new_note,
container, false);
return rootView;
}
}
}
And my XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.src.vicnote.NewNoteActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="#+id/buttonSave"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Save" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/buttonSave"
android:ems="10"
android:gravity="top"
android:inputType="textMultiLine" >
<requestFocus />
</EditText>
</RelativeLayout>
Also I want to ask you what will happen if the text is cyrillic? Will be there any problem?
Can't really tell what your error is without a logCat.
but one thing that might fix your problem is replacing
textData = (EditText) findViewById(R.id.editText);
text = textData.getText().toString();
with
textData = (EditText)getActivity().findViewById(R.id.editText);
text = textData.getText().toString();
// Toast for debugging purposes
Toast.makeText(getActivity(),text,0).show();
When using Fragments you should really read about getView() & getActivity().
Update
where in the xml have you set the text?
you need to set your text to something before you actually call the getText() command.
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/buttonSave"
android:ems="10"
android:gravity="top"
----- add this line ------
android:text="whatever you want"
--------------------------
android:inputType="textMultiLine" >
Good Luck
Adding a getActivity() did the trick before accessing the editText.
For example:
EditText addressText = (EditText) getActivity().findViewById(R.id.location);
getEditableText return an editable object, and you can't edit the object like that, so it is null.
simply use "getText" instead.
I don't know about Cyrillic, but it shouldn't cause any problems.

Categories