Cab and row with checkbox - Android Studio

Hello everybody. I created a contextual action bar with list view with my own adapter. It works perfectly. Now I want to add a check box to select the row, when user click anywhere. I added checkbox to row layout (it contains textview, textview and checkbox) and setEnable(false) because I will programaticaly set clicked/unclicked. But I have a problem how to add a listener to each row in an adapter which will be checking if the row was clicked and set checkbox clicked and change the object value click to true(I only need help with adding listener). Could anybody help me
Here is my adapter code
package com.example.micha.shoppinglist;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Michał on 26.04.2017.
*/
public class RowAdapter extends ArrayAdapter<ProductList>{
private Context context;
private int resource;
private ArrayList<ProductList> data = null;
private RowBeanHolder holder = null;
private boolean longPressed=false;
public RowAdapter @Nonnull Context context, @layoutRes int resource, @Nonnull List<ProductList> data) {
super(context, resource, data);
this.context=context;
this.resource=resource;
this.data=(ArrayList<ProductList>)data;
}
@override
public View getView(int position, final View convertView, ViewGroup parent) {
View row = convertView;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(resource, parent, false);
holder = new RowBeanHolder();
holder.txtTitle=(TextView) row.findViewById(R.id.name);
holder.indicator=(TextView) row.findViewById(R.id.indicator);
holder.checkBox=(CheckBox) row.findViewById(R.id.checkBoxDelete);
row.setTag(holder);
}
else
{
holder = (RowBeanHolder)row.getTag();
}
if(longPressed){
showCheckbox();
}
else{
hideCheckbox();
uncheck();
}
ProductList object = data.get(position);
holder.txtTitle.setText(object.getName());
holder.indicator.setText(object.getToBuy() + "/" + object.getBought());
return row;
}
static class RowBeanHolder {
TextView txtTitle;
TextView indicator;
CheckBox checkBox;
}
public void showCheckbox() {
holder.checkBox.setVisibility(View.VISIBLE);
longPressed=true;
notifyDataSetChanged();
}
public void hideCheckbox() {
holder.checkBox.setVisibility(View.GONE);
longPressed=false;
notifyDataSetChanged();
}
public void uncheck(){
holder.checkBox.setChecked(false);
notifyDataSetChanged();
}
}

Related

[Q] Implement Maps API on Glass?

Has anyone been able to successfully implement the google Maps API on Glass? I am having an issue regarding the manifest xml file.
So, the problem arises when I include:
Code:
<uses-library android:name="com.google.android.maps"/>
in the Manifest file. I get the error:
Code:
Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
So if I remove the line in the manifest, the application will crash upon getting to the map activity which reads:
Main_Activity if needed:
Code:
package com.example.mapping;
import android.app.Activity;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MapActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.mapView)).getMap();
LatLng war = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(war, 13));
map.addMarker(new MarkerOptions()
.title("Mission Drop Zone")
.snippet("Navigate to Enemy Hideout")
.position(war));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.map, 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.mapView) {
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_map, container,
false);
return rootView;
}
}
}
If you require my AndroidManifest let me know. It is not letting me post it because it thinks it is a link to an external page.
Thanks for any help
Solved.
Turns out that glass has limited or no integration with google play services, as a result google maps api is irrelevant. I have solved my issue by integrating MapQuest rather than google maps, and have found it to be much easier to implement into a glass app than trying to hack a maps api integration. Hope this helps anyone else that has had this issue.

[Q] Notiy the user of a variable - Android

Hi y'all. I have recently been trying to make a calculator app in AS. However, the app stops when I click the calculate button. I also wanted to have it notify the user the result contained in the result variable, but the setContentText doesn't want to work. Code:
Code:
package firstapp.stars.com.firstapp;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddScrn extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
final Button button4;
button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView textView4 = (TextView) findViewById(R.id.textView4);
EditText editText7 = (EditText) findViewById(R.id.editText7);
EditText editText8 = (EditText) findViewById(R.id.editText8);
String mynum1=editText7.getText().toString();
String mynum2=editText8.getText().toString();
int result = Integer.parseInt(mynum1) + Integer.parseInt(mynum2);
textView4.setText(Integer.toString(result));
textView4.setText(result);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Calculator - Calculation result:")
String content = String.valueOf(result);
.setContentText(content);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
});
}
@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_add_scrn, 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);
}
}
Help.
Whats-a-username? said:
Hi y'all. I have recently been trying to make a calculator app in AS. However, the app stops when I click the calculate button. I also wanted to have it notify the user the result contained in the result variable, but the setContentText doesn't want to work. Code:
Code:
package firstapp.stars.com.firstapp;
import android.os.Bundle;
import android.app.Notification;
import android.app.NotificationManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class AddScrn extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
final Button button4;
button4 = (Button) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView textView4 = (TextView) findViewById(R.id.textView4);
EditText editText7 = (EditText) findViewById(R.id.editText7);
EditText editText8 = (EditText) findViewById(R.id.editText8);
String mynum1=editText7.getText().toString();
String mynum2=editText8.getText().toString();
int result = Integer.parseInt(mynum1) + Integer.parseInt(mynum2);
textView4.setText(Integer.toString(result));
textView4.setText(result);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Calculator - Calculation result:")
String content = String.valueOf(result);
.setContentText(content);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
});
}
@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_add_scrn, 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);
}
}
Help.
Click to expand...
Click to collapse
Regarding the following code:
textView4.setText(Integer.toString(result));
textView4.setText(result);
Why you assign the value twice?
The first assignment is OK, but the second one need to removed.
The result variable is an Integer type, and when you assign Integer to TextView, it will look for a sting resource id (in the strings xml).
If the id is not found, it can throw an exception.
Yes, but the app still crashes when the button is clicked and still doesn't want to notify me.
Still Active Errors
1. In the setContentTitle it says" ; expected", but when ; is placed, it highlights everything.
2. "Cannot resolve method setContentText".
Whats-a-username? said:
1. In the setContentTitle it says" ; expected", but when ; is placed, it highlights everything.
2. "Cannot resolve method setContentText".
Click to expand...
Click to collapse
Your code is incorrect.
Change you code to the following:
String content = String.valueOf(result);
Notification notification = new Notification.Builder(this)
.setContentTitle("Calculator - Calculation result:")
.setContentText(content).build();

How to long press on my app based webview

Hi guy this is my first application android, i using android studio and i need the help. i long press in not show context menu to download the image, below I leave the code if someone is kind enough to give me help.
Code:
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
WebView webView;
ProgressBar progressBar;
private AudioManager audio;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setSupportZoom(true);
webView.setVerticalScrollBarEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setHorizontalScrollBarEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
//webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("https://alpha.wallhaven.cc/");
//Barra de progreso
progressBar = (ProgressBar) findViewById(R.id.progressBar);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
MainActivity.this.setProgress(progress * 1000);
progressBar.incrementProgressBy(progress);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
}
}
});
/*Adding shortcut for MainActivity
//on Home screen
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);*/
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack()) {
//if Back key pressed and webview can navigate to previous page
webView.goBack();
// go back to previous page
return true;
} else {
finish();
// finish the activity
}
return super.onKeyDown(keyCode, event);
default:
return false;
}
}
}

JSOUP,HtmlParser

Goodmorning ,
I was dabbling with the parser of a web page through Android Studio, the problem is that the code I implemented can't take what i want, I'll explain:
on a website is a web page with the following html:
HTML:
</style>
</head>
<body>
<h1>TITLE PAGE</h1>
<h2><em></em></h2>
<h2>La data prossimae è:</h2>
<p><br />Lunedi 10/10/2016<br />Orario 13.00 - 18.00</p><input type="button" name="chiudi" value="Chiudi" onclick="javascript: self.close();" />
</body>
</html>
With the class JSOUP I'd like to take just the date which is enclosed within <p>, that is, "10/10/2016", is it possible? for now I could only print the page title or the entire text of the page.
here is the class code:
HTML:
package inducesmile.com.androidjsouphtmlparser;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
private Document htmlDocument;
private String htmlPageUrl = "website";
private TextView parsedHtmlNode;
private String htmlContentInStringFormat;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_livepage);
parsedHtmlNode = (TextView)findViewById(R.id.html_content);
Button htmlTitleButton = (Button)findViewById(R.id.button);
htmlTitleButton.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
JsoupAsyncTask jsoupAsyncTask = new JsoupAsyncTask();
jsoupAsyncTask.execute();
}
});
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_livepage, menu);
return true;
}
[user=439709]@override[/user]
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);
}
private class JsoupAsyncTask extends AsyncTask<Void, Void, Void> {
[user=439709]@override[/user]
protected void onPreExecute() {
super.onPreExecute();
}
[user=439709]@override[/user]
protected Void doInBackground(Void... params) {
try {
htmlDocument = Jsoup.connect(htmlPageUrl).get();
htmlContentInStringFormat = htmlDocument.text();
// htmlDocument.title();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
[user=439709]@override[/user]
protected void onPostExecute(Void result) {
parsedHtmlNode.setText(htmlContentInStringFormat);
}
}
}
Thanks to everyone for help!

[CLOSED][DEV] Facebook Messenger notification full messages and add picture

Hello! Because I have a Watch 4 watch, I would like to create a module that converts the Messenger application in such a way that I can see all the messages and the photos sent on my watch. Could someone take a look at this code? And possibly try to compile it into an APK because unfortunately I don't have the right tools right now (I'm on a trip).
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.RemoteViews;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class XposedModule implements IXposedHookLoadPackage {
private static final String TARGET_PACKAGE_NAME = "com.facebook.orca";
private static final String NOTIFICATION_SERVICE = "notification";
[USER=439709]@override[/USER]
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals(TARGET_PACKAGE_NAME)) {
return;
}
XposedBridge.log("Loaded package: " + lpparam.packageName);
XposedHelpers.findAndHookMethod("com.facebook.orca.notify.MessagingNotificationUtil", lpparam.classLoader, "a",
Context.class, Intent.class, String.class, int.class, Bitmap.class, Bundle.class,
new XC_MethodHook() {
[USER=439709]@override[/USER]
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Context context = (Context) param.args[0];
Intent intent = (Intent) param.args[1];
String s = (String) param.args[2];
int i = (int) param.args[3];
Bitmap bitmap = (Bitmap) param.args[4];
Bundle bundle = (Bundle) param.args[5];
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.contentView = new RemoteViews(context.getPackageName(),
context.getResources().getIdentifier("notification_template_base", "layout", "android"));
notification.contentView.setTextViewText(context.getResources().getIdentifier("title", "id", "android"),
s);
notification.contentView.setTextViewText(context.getResources().getIdentifier("text", "id", "android"),
bundle.getString("android.bigText"));
notificationManager.notify(i, notification);
param.setResult(null);
}
});
}
}
I am annoyed with Facebook Messenger because I can't see the full conversation in my watch. So, I decided to create an application that retrieves notifications and displays them. However, I am a beginner and it's a bit overwhelming for me. I created the application, but I don't know why the notifications are not displaying. What do you think about this? Maybe someone can support me in this project. I think many users would benefit from this application.
Here my source: https://github.com/radzi0123/FacebookMessenger
Thread closed on request of OP @radzi0123
Regards
Oswald Boelcke
Senior Moderator

Categories

Resources