2016-03-03 17:46:31 +01:00
|
|
|
/*
|
2016-06-04 03:48:57 +02:00
|
|
|
This file is part of the Diaspora for Android.
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
Diaspora for Android is free software: you can redistribute it and/or modify
|
2016-03-03 17:46:31 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
Diaspora for Android is distributed in the hope that it will be useful,
|
2016-03-03 17:46:31 +01:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-06-04 03:48:57 +02:00
|
|
|
along with the Diaspora for Android.
|
2016-03-03 17:46:31 +01:00
|
|
|
|
|
|
|
If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-03-29 19:38:50 +02:00
|
|
|
package com.github.dfa.diaspora_android.util;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
import android.app.Activity;
|
2016-08-07 23:37:02 +02:00
|
|
|
import android.content.Context;
|
2016-06-04 03:48:57 +02:00
|
|
|
import android.content.Intent;
|
2016-08-07 23:37:02 +02:00
|
|
|
import android.net.Uri;
|
2016-08-27 12:34:08 +02:00
|
|
|
import android.os.Environment;
|
2016-03-03 17:46:31 +01:00
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
import com.github.dfa.diaspora_android.R;
|
2016-07-18 14:02:18 +02:00
|
|
|
|
2016-08-27 16:40:16 +02:00
|
|
|
import java.io.BufferedReader;
|
2016-08-27 12:34:08 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2016-08-27 16:40:16 +02:00
|
|
|
import java.io.InputStreamReader;
|
2016-08-27 12:34:08 +02:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2016-03-03 17:46:31 +01:00
|
|
|
public class Helpers {
|
|
|
|
|
2016-06-04 03:48:57 +02:00
|
|
|
public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) {
|
|
|
|
Intent intent = new Intent(from, to);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
|
|
|
from.startActivity(intent);
|
|
|
|
from.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
|
|
|
|
if (finishFromActivity) {
|
|
|
|
from.finish();
|
|
|
|
}
|
|
|
|
}
|
2016-08-07 23:37:02 +02:00
|
|
|
|
|
|
|
public static void loadUrlInExternalBrowser(Context context, String url) {
|
|
|
|
try {
|
|
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
|
|
context.startActivity(browserIntent);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
|
|
|
}
|
2016-08-27 12:34:08 +02:00
|
|
|
|
|
|
|
public static File createImageFile() throws IOException {
|
|
|
|
// Create an image file name
|
|
|
|
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
|
|
|
|
String imageFileName = "JPEG_" + timeStamp + "_";
|
|
|
|
File storageDir = Environment.getExternalStoragePublicDirectory(
|
|
|
|
Environment.DIRECTORY_PICTURES);
|
|
|
|
return File.createTempFile(
|
|
|
|
imageFileName, /* prefix */
|
|
|
|
".jpg", /* suffix */
|
|
|
|
storageDir /* directory */
|
|
|
|
);
|
|
|
|
}
|
2016-08-27 16:40:16 +02:00
|
|
|
|
|
|
|
public static String readTextfileFromRawRessource(Context context, int rawRessourceId, String linePrefix, String linePostfix) {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
String line = "";
|
|
|
|
BufferedReader br = null;
|
|
|
|
linePrefix = linePrefix == null ? "" : linePrefix;
|
|
|
|
linePostfix = linePostfix == null ? "" : linePostfix;
|
|
|
|
|
|
|
|
try {
|
|
|
|
br = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(rawRessourceId)));
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
sb.append(linePrefix);
|
|
|
|
sb.append(line);
|
|
|
|
sb.append(linePostfix);
|
|
|
|
sb.append("\n");
|
|
|
|
}
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
} finally {
|
|
|
|
if (br != null) {
|
|
|
|
try {
|
|
|
|
br.close();
|
|
|
|
} catch (IOException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String hexColorFromRessourceColor(Context context, int idColor){
|
|
|
|
return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff);
|
|
|
|
}
|
2016-03-03 17:46:31 +01:00
|
|
|
}
|