diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java index 42deefbd..c22c6464 100644 --- a/app/src/main/java/protect/card_locker/MainActivity.java +++ b/app/src/main/java/protect/card_locker/MainActivity.java @@ -1,7 +1,9 @@ package protect.card_locker; +import android.content.ClipData; import android.content.DialogInterface; import android.content.Intent; +import android.content.ClipboardManager; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.database.Cursor; @@ -10,13 +12,16 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; +import android.view.ContextMenu; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import java.util.Calendar; @@ -65,6 +70,8 @@ private void updateLoyaltyCardList() final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, cardCursor); cardList.setAdapter(adapter); + registerForContextMenu(cardList); + cardList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -83,6 +90,39 @@ public void onItemClick(AdapterView parent, View view, int position, long id) }); } + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) + { + super.onCreateContextMenu(menu, v, menuInfo); + if (v.getId()==R.id.list) + { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.card_longclick_menu, menu); + } + } + + @Override + public boolean onContextItemSelected(MenuItem item) + { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); + ListView listView = (ListView) findViewById(R.id.list); + + Cursor cardCursor = (Cursor)listView.getItemAtPosition(info.position); + LoyaltyCard card = LoyaltyCard.toLoyaltyCard(cardCursor); + + if(card != null && item.getItemId() == R.id.action_clipboard) + { + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(card.store, card.cardId); + clipboard.setPrimaryClip(clip); + + Toast.makeText(this, R.string.copy_to_clipboard_toast, Toast.LENGTH_LONG).show(); + return true; + } + + return super.onContextItemSelected(item); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { diff --git a/app/src/main/res/menu/card_longclick_menu.xml b/app/src/main/res/menu/card_longclick_menu.xml new file mode 100644 index 00000000..67ac03c8 --- /dev/null +++ b/app/src/main/res/menu/card_longclick_menu.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 9cd7363d..581afdfa 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -52,4 +52,6 @@ Inserisci carta Seleziona codice a barre Digita il valore del codice a barre, quindi seleziona l\'immagine che rappresenta il codice a barre che vuoi usare. + Copia ID negli appunti + ID della carta copiato negli appunti diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index cab6b8e0..5722758f 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -52,4 +52,6 @@ Voer kaart in Selecteer barcode Voer de waarde van de barcode in en kies daarna de afbeelding die de barcode die je wil gebruiken representeert + Kopieer het ID naar het klembord + Het ID is naar het klembord gekopieerd diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4eb38ac..3ba3f387 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,6 +18,7 @@ Edit Delete OK + Copy ID to clipboard Edit Loyalty Card Add Loyalty Card @@ -55,4 +56,7 @@ Select Barcode Enter the barcode value then select the image which represents the barcode you want to use + + Card ID copied to clipboard + \ No newline at end of file