Gutyn
9 years ago
36 changed files with 1695 additions and 1189 deletions
File diff suppressed because it is too large
@ -1,7 +1,48 @@ |
|||
package com.breadwallet.presenter; |
|||
|
|||
import android.app.Activity; |
|||
import android.app.Application; |
|||
import android.os.Handler; |
|||
import android.view.Gravity; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
import android.widget.TextView; |
|||
import android.widget.Toast; |
|||
|
|||
import com.breadwallet.R; |
|||
|
|||
/** |
|||
* Created by Mihail on 7/22/15. |
|||
*/ |
|||
public class BreadWalletApp { |
|||
public class BreadWalletApp extends Application { |
|||
public static final String TAG = "BreadWalletApp"; |
|||
private boolean customToastAvailable = true; |
|||
|
|||
/** |
|||
* Shows a custom toast using the given string as a paramater, |
|||
* |
|||
* @param message the message to be shown in the custom toast |
|||
*/ |
|||
public void showCustomToast(Activity app, String message, int yOffSet, int duration) { |
|||
if (customToastAvailable) { |
|||
customToastAvailable = false; |
|||
new Handler().postDelayed(new Runnable() { |
|||
@Override |
|||
public void run() { |
|||
customToastAvailable = true; |
|||
} |
|||
}, 1000); |
|||
LayoutInflater inflater = app.getLayoutInflater(); |
|||
View layout = inflater.inflate(R.layout.toast, |
|||
(ViewGroup) app.findViewById(R.id.toast_layout_root)); |
|||
TextView text = (TextView) layout.findViewById(R.id.toast_text); |
|||
text.setText(message); |
|||
Toast toast = new Toast(getApplicationContext()); |
|||
toast.setGravity(Gravity.BOTTOM, 0, yOffSet); |
|||
toast.setDuration(duration); |
|||
toast.setView(layout); |
|||
toast.show(); |
|||
} |
|||
} |
|||
} |
|||
|
@ -1,7 +1,86 @@ |
|||
package com.breadwallet.presenter.fragments.allsettings.settings; |
|||
|
|||
import android.content.SharedPreferences; |
|||
import android.os.Bundle; |
|||
import android.support.v4.app.Fragment; |
|||
import android.util.Log; |
|||
import android.view.LayoutInflater; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
import android.widget.AdapterView; |
|||
import android.widget.ArrayAdapter; |
|||
import android.widget.Button; |
|||
import android.widget.ListView; |
|||
import android.widget.TextView; |
|||
import android.widget.Toast; |
|||
|
|||
import com.breadwallet.R; |
|||
import com.breadwallet.presenter.BreadWalletApp; |
|||
import com.breadwallet.presenter.activities.MainActivity; |
|||
import com.breadwallet.tools.animation.FragmentAnimator; |
|||
import com.breadwallet.tools.others.CurrencyManager; |
|||
|
|||
/** |
|||
* Created by Mihail on 7/14/15. |
|||
*/ |
|||
public class FragmentCurrency { |
|||
public class FragmentCurrency extends Fragment { |
|||
public static final String TAG = "FragmentCurrency"; |
|||
public static final String CURRENT_CURRENCY = "currentCurrency"; |
|||
private ListView currencyList; |
|||
private MainActivity app; |
|||
private Button currencyRefresh; |
|||
private TextView noInternetConnection; |
|||
private ArrayAdapter adapter; |
|||
|
|||
@Override |
|||
public View onCreateView(LayoutInflater inflater, |
|||
ViewGroup container, Bundle savedInstanceState) { |
|||
// The last two arguments ensure LayoutParams are inflated
|
|||
// properly.
|
|||
View rootView = inflater.inflate( |
|||
R.layout.fragment_local_currency, container, false); |
|||
app = MainActivity.getApp(); |
|||
currencyList = (ListView) rootView.findViewById(R.id.currency_list_view); |
|||
currencyRefresh = (Button) rootView.findViewById(R.id.currencyRefresh); |
|||
noInternetConnection = (TextView) rootView.findViewById(R.id.noInternetConnectionText); |
|||
|
|||
currencyRefresh.setOnClickListener(new View.OnClickListener() { |
|||
@Override |
|||
public void onClick(View v) { |
|||
adapter = CurrencyManager.getCurrencyAddapterIfReady(); |
|||
tryAndSetAdapter(); |
|||
} |
|||
}); |
|||
adapter = CurrencyManager.getCurrencyAddapterIfReady(); |
|||
tryAndSetAdapter(); |
|||
currencyList.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
|||
@Override |
|||
public void onItemClick(AdapterView<?> parent, View view, |
|||
int position, long id) { |
|||
TextView tmp = (TextView) view.findViewById(R.id.currency_item_text); |
|||
final String selectedCurrency = tmp.getText().toString(); |
|||
SharedPreferences settings = getActivity().getSharedPreferences(MainActivity.PREFS_NAME, 0); |
|||
SharedPreferences.Editor editor = settings.edit(); |
|||
editor.putString(CURRENT_CURRENCY, selectedCurrency.substring(0, 3)); |
|||
editor.commit(); |
|||
FragmentAnimator.animateSlideToRight(app); |
|||
Log.d(TAG, "Selected item's text: " + selectedCurrency); |
|||
} |
|||
}); |
|||
|
|||
return rootView; |
|||
} |
|||
|
|||
public void tryAndSetAdapter() { |
|||
if (adapter.getCount() > 0) { |
|||
currencyList.setAdapter(adapter); |
|||
currencyRefresh.setVisibility(View.GONE); |
|||
noInternetConnection.setVisibility(View.GONE); |
|||
} else { |
|||
((BreadWalletApp) app.getApplicationContext()).showCustomToast(getActivity(), "No internet connection", 500, Toast.LENGTH_SHORT); |
|||
currencyRefresh.setVisibility(View.VISIBLE); |
|||
noInternetConnection.setVisibility(View.VISIBLE); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
@ -1,7 +1,120 @@ |
|||
package com.breadwallet.tools.others; |
|||
|
|||
import android.content.Context; |
|||
import android.net.ConnectivityManager; |
|||
import android.net.NetworkInfo; |
|||
import android.os.AsyncTask; |
|||
import android.os.Handler; |
|||
import android.util.Log; |
|||
import android.widget.ArrayAdapter; |
|||
|
|||
import com.breadwallet.R; |
|||
import com.breadwallet.presenter.activities.MainActivity; |
|||
|
|||
import org.json.JSONArray; |
|||
import org.json.JSONException; |
|||
import org.json.JSONObject; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Timer; |
|||
import java.util.TimerTask; |
|||
|
|||
/** |
|||
* Created by Mihail on 7/22/15. |
|||
*/ |
|||
public class CurrencyManager { |
|||
private static MainActivity app = MainActivity.getApp(); |
|||
public static final String TAG = "CurrencyManager"; |
|||
private static ArrayAdapter currencyAdapter; |
|||
private static Timer timer; |
|||
private static TimerTask timerTask; |
|||
private static final Handler handler = new Handler(); |
|||
|
|||
public static boolean isNetworkAvailable() { |
|||
ConnectivityManager connectivityManager |
|||
= (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE); |
|||
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); |
|||
return activeNetworkInfo != null && activeNetworkInfo.isConnected(); |
|||
} |
|||
|
|||
public static List<String> getCurrencies() { |
|||
List<String> list = new ArrayList<>(); |
|||
if (isNetworkAvailable()) { |
|||
JSONArray arr = null; |
|||
arr = JsonParser.getJSonArray("https://bitpay.com/rates"); |
|||
for (int i = 1; i < arr.length(); i++) { |
|||
String tmp = null; |
|||
try { |
|||
JSONObject tmpObj = (JSONObject) arr.get(i); |
|||
tmp = tmpObj.getString("code") + " - " + tmpObj.getString("name"); |
|||
} catch (JSONException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
list.add(tmp); |
|||
} |
|||
} else { |
|||
|
|||
} |
|||
return list; |
|||
} |
|||
|
|||
public static class GetCurrenciesTask extends AsyncTask { |
|||
List<String> tmp; |
|||
|
|||
@Override |
|||
protected Object doInBackground(Object[] params) { |
|||
currencyAdapter = new ArrayAdapter(app, R.layout.currency_list_item); |
|||
tmp = getCurrencies(); |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
protected void onPostExecute(Object o) { |
|||
super.onPostExecute(o); |
|||
currencyAdapter.clear(); |
|||
Log.e(TAG, "Cleared: adapter count: " + currencyAdapter.getCount()); |
|||
currencyAdapter.addAll(tmp); |
|||
Log.e(TAG, "Filled: adapter count: " + currencyAdapter.getCount()); |
|||
} |
|||
} |
|||
|
|||
public static ArrayAdapter getCurrencyAddapterIfReady() { |
|||
new GetCurrenciesTask().execute(); |
|||
return currencyAdapter; |
|||
} |
|||
|
|||
public static void initializeTimerTask() { |
|||
|
|||
timerTask = new TimerTask() { |
|||
public void run() { |
|||
|
|||
//use a handler to run a toast that shows the current timestamp
|
|||
handler.post(new Runnable() { |
|||
public void run() { |
|||
new GetCurrenciesTask().execute(); |
|||
} |
|||
}); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
public static void startTimer() { |
|||
//set a new Timer
|
|||
timer = new Timer(); |
|||
|
|||
//initialize the TimerTask's job
|
|||
initializeTimerTask(); |
|||
|
|||
//schedule the timer, after the first 5000ms the TimerTask will run every 10000ms
|
|||
timer.schedule(timerTask, 0, 30000); //
|
|||
} |
|||
|
|||
public static void stoptimertask() { |
|||
//stop the timer, if it's not already null
|
|||
if (timer != null) { |
|||
timer.cancel(); |
|||
timer = null; |
|||
} |
|||
} |
|||
} |
|||
|
@ -1,7 +1,65 @@ |
|||
package com.breadwallet.tools.others; |
|||
|
|||
import android.util.Log; |
|||
|
|||
import org.json.JSONArray; |
|||
import org.json.JSONException; |
|||
import org.json.JSONObject; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.InputStreamReader; |
|||
import java.net.URL; |
|||
import java.net.URLConnection; |
|||
import java.nio.charset.Charset; |
|||
|
|||
/** |
|||
* Created by Mihail on 7/14/15. |
|||
*/ |
|||
public class JsonParser { |
|||
public static final String TAG = "JsonParser"; |
|||
|
|||
public static JSONArray getJSonArray(String URL) { |
|||
String jsonString = callURL(URL); |
|||
System.out.println("\n\njsonString: " + jsonString); |
|||
JSONArray jsonArray = null; |
|||
try { |
|||
JSONObject obj = new JSONObject(jsonString); |
|||
|
|||
jsonArray = obj.getJSONArray("data"); |
|||
Log.e(TAG,"\n\njsonArray: " + jsonArray); |
|||
} catch (JSONException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return jsonArray; |
|||
} |
|||
|
|||
private static String callURL(String myURL) { |
|||
System.out.println("Requested URL:" + myURL); |
|||
StringBuilder sb = new StringBuilder(); |
|||
URLConnection urlConn = null; |
|||
InputStreamReader in = null; |
|||
try { |
|||
URL url = new URL(myURL); |
|||
urlConn = url.openConnection(); |
|||
if (urlConn != null) |
|||
urlConn.setReadTimeout(60 * 1000); |
|||
if (urlConn != null && urlConn.getInputStream() != null) { |
|||
in = new InputStreamReader(urlConn.getInputStream(), |
|||
Charset.defaultCharset()); |
|||
BufferedReader bufferedReader = new BufferedReader(in); |
|||
if (bufferedReader != null) { |
|||
int cp; |
|||
while ((cp = bufferedReader.read()) != -1) { |
|||
sb.append((char) cp); |
|||
} |
|||
bufferedReader.close(); |
|||
} |
|||
} |
|||
in.close(); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException("Exception while calling URL:" + myURL, e); |
|||
} |
|||
|
|||
return sb.toString(); |
|||
} |
|||
} |
|||
|
@ -1,7 +1,87 @@ |
|||
package com.breadwallet.tools.others; |
|||
|
|||
/** |
|||
* Created by Mihail on 7/14/15. |
|||
*/ |
|||
import android.annotation.SuppressLint; |
|||
import android.content.ClipData; |
|||
import android.content.ClipboardManager; |
|||
import android.content.ContentResolver; |
|||
import android.content.Context; |
|||
import android.net.Uri; |
|||
|
|||
|
|||
public class MyClipboardManager { |
|||
|
|||
@SuppressLint("NewApi") |
|||
@SuppressWarnings("deprecation") |
|||
public static boolean copyToClipboard(Context context, String text) { |
|||
try { |
|||
int sdk = android.os.Build.VERSION.SDK_INT; |
|||
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { |
|||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context |
|||
.getSystemService(context.CLIPBOARD_SERVICE); |
|||
clipboard.setText(text); |
|||
} else { |
|||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context |
|||
.getSystemService(context.CLIPBOARD_SERVICE); |
|||
android.content.ClipData clip = android.content.ClipData |
|||
.newPlainText("message", text); |
|||
clipboard.setPrimaryClip(clip); |
|||
} |
|||
return true; |
|||
} catch (Exception e) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
@SuppressLint("NewApi") |
|||
public static String readFromClipboard(Context context) { |
|||
int sdk = android.os.Build.VERSION.SDK_INT; |
|||
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { |
|||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context |
|||
.getSystemService(context.CLIPBOARD_SERVICE); |
|||
return clipboard.getText().toString(); |
|||
} else { |
|||
ClipboardManager clipboard = (ClipboardManager) context |
|||
.getSystemService(Context.CLIPBOARD_SERVICE); |
|||
|
|||
// Gets a content resolver instance
|
|||
ContentResolver cr = context.getContentResolver(); |
|||
|
|||
// Gets the clipboard data from the clipboard
|
|||
ClipData clip = clipboard.getPrimaryClip(); |
|||
if (clip != null) { |
|||
|
|||
String text = null; |
|||
String title = null; |
|||
|
|||
// Gets the first item from the clipboard data
|
|||
ClipData.Item item = clip.getItemAt(0); |
|||
|
|||
// Tries to get the item's contents as a URI pointing to a note
|
|||
Uri uri = item.getUri(); |
|||
|
|||
// If the contents of the clipboard wasn't a reference to a
|
|||
// note, then
|
|||
// this converts whatever it is to text.
|
|||
if (text == null) { |
|||
text = coerceToText(context, item).toString(); |
|||
} |
|||
|
|||
return text; |
|||
} |
|||
} |
|||
return ""; |
|||
} |
|||
|
|||
@SuppressLint("NewApi") |
|||
public static CharSequence coerceToText(Context context, ClipData.Item item) { |
|||
// If this Item has an explicit textual value, simply return that.
|
|||
CharSequence text = item.getText(); |
|||
if (text != null) { |
|||
return text; |
|||
} else { |
|||
return "no text"; |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
@ -1,6 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<item android:drawable="@drawable/buttonblue" android:state_focused="true" android:state_pressed="true" /> |
|||
<item android:drawable="@drawable/buttonbluepressed" android:state_focused="false" android:state_pressed="true" /> |
|||
<item android:drawable="@drawable/buttonbluepressed" android:state_pressed="true" /> |
|||
<item android:drawable="@drawable/buttonblue" /> |
|||
</selector> |
@ -1,32 +1,15 @@ |
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:id="@+id/fragment_decoder_layout" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:background="@color/black" |
|||
android:id="@+id/fragment_decoder_layout"> |
|||
|
|||
<!--<com.breadwallet.tools.qrcode.QRCodeReaderView--> |
|||
<!--android:id="@+id/qrdecoderview"--> |
|||
<!--android:layout_width="match_parent"--> |
|||
<!--android:layout_height="match_parent"--> |
|||
<!--android:layout_alignParentLeft="true"--> |
|||
<!--android:layout_alignParentTop="true" />--> |
|||
|
|||
<TextView |
|||
android:id="@+id/exampleTextView" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentTop="true" |
|||
android:layout_centerHorizontal="true" |
|||
android:layout_marginTop="20dp" |
|||
android:text="----" |
|||
android:textAppearance="?android:attr/textAppearanceLarge" /> |
|||
android:background="@color/black"> |
|||
|
|||
<ImageView |
|||
android:id="@+id/red_line_image" |
|||
android:id="@+id/camera_guide_image" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentLeft="true" |
|||
android:layout_below="@+id/exampleTextView" |
|||
android:src="@drawable/red_line" /> |
|||
android:layout_alignParentStart="true" |
|||
android:layout_centerVertical="true" |
|||
android:src="@drawable/cameraguide" /> |
|||
|
|||
</RelativeLayout> |
@ -1,32 +1,57 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:id="@+id/mainfragment" android:layout_width="match_parent" |
|||
android:layout_height="match_parent" android:orientation="vertical"> |
|||
android:id="@+id/mainfragment" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:orientation="vertical"> |
|||
|
|||
|
|||
<TextView android:id="@+id/maintextsendmoney" android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" android:layout_below="@+id/maintextbreadwallet" |
|||
android:layout_centerHorizontal="true" android:layout_gravity="center" |
|||
android:layout_marginTop="120dp" android:text="send money:" android:textSize="24sp" /> |
|||
|
|||
<Button android:id="@+id/mainbuttonscanqrcode" android:layout_width="270dp" |
|||
android:layout_height="60dp" android:layout_below="@+id/maintextsendmoney" android:layout_centerHorizontal="true" |
|||
android:layout_gravity="center" android:layout_marginTop="32dp" |
|||
android:background="@drawable/button" android:text=" scan QR code " |
|||
android:textColor="@color/darkblue" android:textSize="20sp" /> |
|||
<TextView |
|||
android:id="@+id/maintextsendmoney" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:layout_below="@+id/maintextbreadwallet" |
|||
android:layout_centerHorizontal="true" |
|||
android:layout_gravity="center" |
|||
android:layout_marginTop="120dp" |
|||
android:text="send money:" |
|||
android:textSize="24sp" /> |
|||
|
|||
<Button android:id="@+id/mainbuttonpayaddressfromclipboard" |
|||
android:layout_width="270dp" android:layout_height="60dp" |
|||
android:layout_below="@+id/mainbuttonscanqrcode" android:layout_centerHorizontal="true" |
|||
android:layout_gravity="center" android:layout_marginTop="50dp" |
|||
android:background="@drawable/button" android:text=" pay address from clipboard " android:textColor="@color/darkblue" |
|||
<Button |
|||
android:id="@+id/mainbuttonscanqrcode" |
|||
android:layout_width="270dp" |
|||
android:layout_height="60dp" |
|||
android:layout_below="@+id/maintextsendmoney" |
|||
android:layout_centerHorizontal="true" |
|||
android:layout_gravity="center" |
|||
android:layout_marginTop="32dp" |
|||
android:background="@drawable/button" |
|||
android:text="scan QR code" |
|||
android:textColor="@color/darkblue" |
|||
android:textSize="20sp" /> |
|||
|
|||
<TextView android:id="@+id/textView" android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" android:layout_below="@+id/mainbuttonpayaddressfromclipboard" |
|||
<Button |
|||
android:id="@+id/mainbuttonpayaddressfromclipboard" |
|||
android:layout_width="270dp" |
|||
android:layout_height="60dp" |
|||
android:layout_below="@+id/mainbuttonscanqrcode" |
|||
android:layout_centerHorizontal="true" |
|||
android:layout_gravity="center" android:layout_marginTop="15dp" |
|||
android:text="address" /> |
|||
android:layout_gravity="center" |
|||
android:layout_marginTop="50dp" |
|||
android:background="@drawable/buttonblue" |
|||
android:text="pay address from clipboard " |
|||
android:textColor="@color/darkblue" |
|||
android:textSize="20sp" /> |
|||
|
|||
<EditText |
|||
android:layout_marginTop="20dp" |
|||
android:textColor="@color/grey" |
|||
android:id="@+id/addresseditText" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="150dp" |
|||
android:text="The address" |
|||
android:textAlignment="gravity" |
|||
android:layout_gravity="center_horizontal" |
|||
android:background="#00000000" /> |
|||
|
|||
</LinearLayout> |
@ -1,5 +1,14 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:layout_width="match_parent" android:layout_height="match_parent"> |
|||
|
|||
</RelativeLayout> |
|||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" |
|||
android:id="@+id/currency_item_text" |
|||
android:layout_width="fill_parent" |
|||
android:layout_height="wrap_content" |
|||
android:layout_alignParentStart="true" |
|||
android:layout_alignParentTop="true" |
|||
android:textColor="@color/dark_grey" |
|||
android:text="" |
|||
android:gravity="center_vertical" |
|||
android:paddingStart="?android:attr/listPreferredItemPaddingStart" |
|||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" |
|||
android:minHeight="?android:attr/listPreferredItemHeightSmall" |
|||
android:textAppearance="?android:attr/textAppearanceLarge" /> |
|||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue