|
What do you mean by the term, "realize"? Does that mean to develop?
Creating this feature from scratch won't be a good idea, as you would have to handle many events such as drag events (for the drawer). What you need to use is, a Navigation Drawer activity. Navigation drawer supports the features that you need to use. That is how you see the applications to be working in Android with this feature. Android manages showing the list view of the drawer using the z-index in the application and the rest of the stuff would be managed by Android too, like showing the content, changing which layout or content to show etc.
For more on this, please go through, Creating a Navigation Drawer | Android Developers[^]
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I am able to make a bluetooth connection with a GNSS Device, but the problem is that, i am not able to stay connected with the device or in keeping the connection alive with the device in my entire application.
|
|
|
|
|
|
you could keep connection in a global manager instead of a activity, you can refer to this
|
|
|
|
|
How and where are you establishing said connection? What are you doing in methods like onPause() , onStop() , and onDestroy() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Here is the solution to keep the connection alive across the entire app :-
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
bluetoothSocket = Globals.bluetoothDevice.createRfcommSocketToServiceRecord(Globals.DEFAULT_SPP_UUID);
bluetoothSocket.connect();
} catch (IOException e) {
e.printStackTrace();
}
no need to use those methods.
|
|
|
|
|
 When you are Selecting A device to connect and when you are click on the device list item for requesting a connection to the device use AsyncTask
and put the connect method inside the AsyncTask like this :-
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
bluetoothSocket = Globals.bluetoothDevice.createRfcommSocketToServiceRecord(Globals.DEFAULT_SPP_UUID);
bluetoothSocket.connect();
// After successful connect you can open InputStream
} catch (IOException e) {
e.printStackTrace();
}
Here is the full code for the same problem that i have cracked :-
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
lablelexconnected.setText("Connecting ...");
bdDevice = arrayListBluetoothDevices.get(position);
//bdClass = arrayListBluetoothDevices.get(position)
// Toast.makeText(getApplicationContext()," " + bdDevice.getAddress(),Toast.LENGTH_SHORT).show();
Log.i("Log", "The dvice : " + bdDevice.toString());
bdDevice = bluetoothAdapter.getRemoteDevice(bdDevice.getAddress());
Globals.bluetoothDevice = bluetoothAdapter.getRemoteDevice(bdDevice.getAddress());
System.out.println("Device in GPS Settings : " + bdDevice);
// startService(new Intent(getApplicationContext(),MyService.class));
/* Intent i = new Intent(GpsSettings.this, MyService.class);
startService(i);*/
// finish();
// connectDevice();
AsyncTask.execute(new Runnable() {
@Override
public void run() {
try {
bluetoothSocket = Globals.bluetoothDevice.createRfcommSocketToServiceRecord(Globals.DEFAULT_SPP_UUID);
bluetoothSocket.connect();
// After successful connect you can open InputStream
InputStream in = null;
in = bluetoothSocket.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
br = new BufferedReader(isr);
while (found == 0) {
String nmeaMessage = br.readLine();
Log.d("NMEA", nmeaMessage);
// parse NMEA messages
sentence = nmeaMessage;
System.out.println("Sentence : " + sentence);
if (sentence.startsWith("$GPRMC")) {
String[] strValues = sentence.split(",");
System.out.println("StrValues : " + strValues[3] + " " + strValues[5] + " " + strValues[8]);
if (strValues[3].equals("") && strValues[5].equals("") && strValues[8].equals("")) {
Toast.makeText(getApplicationContext(), "Location Not Found !!! ", Toast.LENGTH_SHORT).show();
} else {
latitude = Double.parseDouble(strValues[3]);
if (strValues[4].charAt(0) == 'S') {
latitude = -latitude;
}
longitude = Double.parseDouble(strValues[5]);
if (strValues[6].charAt(0) == 'W') {
longitude = -longitude;
}
course = Double.parseDouble(strValues[8]);
// Toast.makeText(getApplicationContext(), "latitude=" + latitude + " ; longitude=" + longitude + " ; course = " + course, Toast.LENGTH_SHORT).show();
System.out.println("latitude=" + latitude + " ; longitude=" + longitude + " ; course = " + course);
// found = 1;
NMEAToDecimalConverter(latitude, longitude);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
});
BDW Richard MacCutchan this is my another account. I have solved My Problem.
modified 14-Sep-16 5:52am.
|
|
|
|
|
I have problem with layout in my application. I'm using list view and I have defined a custom list row. The program is correctly executed, but layout has some problem.
The space between two consecutive row is excessive...
This is XML code that I use in application layout (main) "activityMain.xml"
<?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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="No contents" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<ListView
android:id="@+id/listView_InfoOnLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:background="@drawable/bkgreen"
android:layout_marginTop="15dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:footerDividersEnabled="false"
android:layout_alignParentEnd="true"
android:divider="@null"
android:dividerHeight="5dp"
android:layout_alignParentStart="true"
android:scrollIndicators="right"
android:clickable="true" />
</RelativeLayout>
and this is the custm row in XML resource ("list_row.xml")
<?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="90dip"
android:background="@drawable/bkglavander"
android:orientation="vertical"
android:padding="5dip" >
<!-- ListRow Left sied Image -->
<LinearLayout android:id="@+id/thumbnail"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="80dip"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@drawable/bkgorange"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/imaginiRSS"
android:layout_width="50dip"
android:layout_height="60dip"
android:src="@drawable/bkgblack"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true">
<!-- Title Of rss-->
<TextView
android:id="@+id/titoliRSS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=". TITLE"
android:textColor="#ff00aa00"
android:typeface="sans"
android:textSize="20dip"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:textStyle="bold"/>
<!-- Link -->
<TextView
android:id="@+id/linksRSS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/titoliRSS"
android:gravity="right"
android:text=". LINK"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:textSize="12dip"
android:textColor="#ff0000ff"
android:textStyle="bold"/>
<!-- Description -->
<TextView
android:id="@+id/descrizioniRSS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/titoliRSS"
android:textColor="#343434"
android:textSize="15dip"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"
android:layout_marginTop="1dip"
android:text=". DESC." />
</LinearLayout>
</LinearLayout>
</LinearLayout>
What is wrong, please?
|
|
|
|
|
Andy_Bell wrote: android:layout_height="90dip" Have you considered values other than 90 ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yes of course. Reducing this value I can restrict row (defined in "list_row.xml") but the problem remain: space between 2 line remains the same.
I think it's like the problem is in ListView and not in the custom row.....
|
|
|
|
|
A picture would help.
You have a bunch of extra stuff on each of those widgets, both files. I would suggest trimming away everything that is not 100% necessary and then build them back up until the problem reappears.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Good evening.
I try to download picture form url and insert in Image View. I use this code to do it:
public Bitmap getBitmapFromURL(String src) {
Bitmap myBitmap = null;
try {
java.net.URL url = new java.net.URL(src);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
I just want to ask you, there is problem to do so, or is it inefficient?
Closing this application, remains the downloaded picture remains in memory?
If I want to free memory resource, how can I cancel this files (accumulated in time)?
|
|
|
|
|
Andy_Bell wrote: Closing this application, remains the downloaded picture remains in memory? Only until the Android OS removes the application from memory. You could save space by immediately saving the bitmap on disk and only loading it into memory when you want to display it. Resources will get freed when the Bitmap object goes out of scop or is otherwise disposed.
|
|
|
|
|
Ok so unistalling my application, user can completly removed images downloaded.
I have another question about. Where is the folder that contains those files?
|
|
|
|
|
Andy_Bell wrote: Where is the folder that contains those files? All depends where you save them. There was an excellent article about storage handling here on CodeProject, but the author has removed it. I guess you will need to do some searching for yourself to find something similar.
|
|
|
|
|
I haven't save file, I use only code attached in previous post. What I've been doing is connecting with HttpURLConnection at url of the image, downloading file and reading input stream. I think, doing in this way, I have a temp copy of image file stored in Android folder, but I don't know what it is.Isn't it?
Thank you!
|
|
|
|
|
Doing it this way the file only exists in virtual storage. As soon as the Bitmap object goes out of scope (e.g the object is disposed) then the data is destroyed.
|
|
|
|
|
Wonderful.
Just another curiosity, if I can... If I start thread with Thread instance and Run method, how can I kill this and, if it's required, restarting when it's required. Can I use thread.destroy() ?
|
|
|
|
|
Sorry, not sure; I have not done much with Threads on Android.
|
|
|
|
|
No matter, I open another discussion. Thanks, you've been helpful!
|
|
|
|
|
I would be inclined to use AsyncTask instead. It's easily stoppable (without corrupting other areas).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
how to get or set a Multidimensional array variable value when using a global class. tried different ways no success.
public class Global extends Application {
private String [][][] myarray=new String[10][10][10];
public String[][][] getMyarray() {
return myarray;
}
public void setMyarray(String[][][] myarray) {
this.myarray = myarray;
}
}
my activity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
class MyView extends View
{
public MyView(Context context) {
super(context);
final Global globalVariable = (Global) getApplicationContext();
(globalVariable).setMyarray[2][2][1]("me");
final String name = globalVariable.getMyarray[2][2][1];
}
}
}
|
|
|
|
|
It is not obvious why you need this array or exactly what you are trying to do with it. You also need to instantiate a Global object somewhere, rather than trying to call getApplicationContext and trying to cast it to a Global .
However your reference code needs to look like:
Global myGlobal = new Global();
string[][][] myArray = myGlobal.getMyarray();
myArray[2][2][1] = "me";
final String name = myArray[2][2][1];
Although the above code will (sort of) work it is still lacking context so you need to provide more information on what you are trying to do.
|
|
|
|
|
thanks Richard, your code work great.
|
|
|
|
|
I question what it is that you are doing that requires a three dimensional array. Chances are a much simpler (i.e., easier to maintain and understand) way exists.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|