-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
925 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
app/src/main/java/net/rachel030219/hashchecker/AboutActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
Copyright 2016 Rachel030219 | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package net.rachel030219.hashchecker; | ||
|
||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.net.Uri; | ||
import android.view.View; | ||
import android.view.MenuItem; | ||
import android.view.WindowManager; | ||
import android.widget.TextView; | ||
import android.content.Intent; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.res.Resources; | ||
|
||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AlertDialog; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
|
||
public class AboutActivity extends AppCompatActivity{ | ||
TextView mPreferenceFragmentCompat; | ||
TextView mMaterialSettingsActivityDemo; | ||
|
||
TextView mAboutMe; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState){ | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.about); | ||
|
||
Toolbar mToolbar = (Toolbar)findViewById(R.id.about_toolbar); | ||
mToolbar.setTitle(getTitle()); | ||
setSupportActionBar(mToolbar); | ||
|
||
ActionBar mActionBar = getSupportActionBar(); | ||
mActionBar.setHomeButtonEnabled(true); | ||
mActionBar.setDisplayHomeAsUpEnabled(true); | ||
|
||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { | ||
WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes(); | ||
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags); | ||
} | ||
|
||
bindViews(); | ||
} | ||
|
||
private void bindViews(){ | ||
Resources res = getResources(); | ||
mPreferenceFragmentCompat = (TextView)findViewById(R.id.about_projects_preferencefragment); | ||
mPreferenceFragmentCompat.setOnClickListener(new OnProjectClick(this,res.getString(R.string.about_projects_preferencefragment),res.getString(R.string.about_projects_preferencefragment_license),"https://github.com/Machinarius/PreferenceFragment-Compat")); | ||
mMaterialSettingsActivityDemo = (TextView)findViewById(R.id.about_projects_materialsettingsactivitydemo); | ||
mMaterialSettingsActivityDemo.setOnClickListener(new OnProjectClick(this,res.getString(R.string.about_projects_materialsettingsactivitydemo),res.getString(R.string.about_projects_materialsettingsactivitydemo_license),"https://drakeet.me/material-design-settings-activity")); | ||
|
||
mAboutMe = (TextView)findViewById(R.id.about_me); | ||
mAboutMe.setOnClickListener(new View.OnClickListener(){ | ||
@Override | ||
public void onClick(View v){ | ||
AlertDialog.Builder builder = new AlertDialog.Builder(AboutActivity.this); | ||
builder.setTitle(R.string.about_me_title); | ||
builder.setMessage(R.string.about_me_content); | ||
builder.setPositiveButton("GOT IT",null); | ||
builder.show(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item){ | ||
// TODO: Implement this method | ||
switch(item.getItemId()){ | ||
case android.R.id.home: | ||
finish(); | ||
break; | ||
} | ||
return true; | ||
} | ||
|
||
class OnProjectClick implements View.OnClickListener{ | ||
Context context; | ||
String title; | ||
String license; | ||
String url; | ||
|
||
OnProjectClick(Context context,String title,String license,String url){ | ||
this.context = context; | ||
this.title = title; | ||
this.license = license; | ||
this.url = url; | ||
} | ||
|
||
@Override | ||
public void onClick(View v){ | ||
AlertDialog.Builder dialog = new AlertDialog.Builder(context); | ||
dialog.setTitle(title); | ||
dialog.setMessage(license); | ||
dialog.setPositiveButton("GOT IT",null); | ||
dialog.setNegativeButton("MORE...",new DialogInterface.OnClickListener(){ | ||
@Override | ||
public void onClick(DialogInterface dialog,int i){ | ||
Uri uri = Uri.parse(url); | ||
Intent intent = new Intent(Intent.ACTION_VIEW,uri); | ||
startActivity(intent); | ||
} | ||
}); | ||
dialog.show(); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/net/rachel030219/hashchecker/ClipboardManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2016 Rachel030219 | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package net.rachel030219.hashchecker; | ||
|
||
public class ClipboardManager{ | ||
android.text.ClipboardManager oldManager; | ||
android.content.ClipboardManager newManager; | ||
|
||
boolean newAPI = android.os.Build.VERSION.SDK_INT >= 11; | ||
|
||
public ClipboardManager(android.content.Context context){ | ||
if(newAPI){ | ||
newManager = (android.content.ClipboardManager)context.getSystemService(context.CLIPBOARD_SERVICE); | ||
} else { | ||
oldManager = (android.text.ClipboardManager)context.getSystemService(context.CLIPBOARD_SERVICE); | ||
} | ||
} | ||
|
||
public void set(String text){ | ||
if(newAPI){ | ||
newManager.setPrimaryClip(android.content.ClipData.newPlainText(null, text)); | ||
} else { | ||
oldManager.setText(text); | ||
} | ||
} | ||
|
||
public CharSequence get(){ | ||
if(newAPI){ | ||
return newManager.getPrimaryClip().getItemAt(0).getText(); | ||
} else { | ||
return oldManager.getText(); | ||
} | ||
} | ||
|
||
public boolean has(){ | ||
if(newAPI){ | ||
return newManager.hasPrimaryClip(); | ||
} else { | ||
return oldManager.hasText(); | ||
} | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
app/src/main/java/net/rachel030219/hashchecker/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
Copyright 2016 Rachel030219 | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
// From Rachel:I got this from a answer under Stack Overflow. Thanks him! | ||
|
||
package net.rachel030219.hashchecker; | ||
|
||
import android.os.Build; | ||
import android.os.Environment; | ||
import android.net.Uri; | ||
import android.content.Context; | ||
import android.content.ContentUris; | ||
import android.database.Cursor; | ||
import android.provider.MediaStore; | ||
import android.provider.DocumentsContract; | ||
|
||
public class FileUtils{ | ||
/** | ||
* Get a file path from a Uri. This will get the the path for Storage Access | ||
* Framework Documents, as well as the _data field for the MediaStore and | ||
* other file-based ContentProviders. | ||
* | ||
* @param context The context. | ||
* @param uri The Uri to query. | ||
* @author paulburke | ||
*/ | ||
public static String getPath(final Context context, final Uri uri) { | ||
|
||
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; | ||
|
||
// DocumentProvider | ||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { | ||
// ExternalStorageProvider | ||
if (isExternalStorageDocument(uri)) { | ||
final String docId = DocumentsContract.getDocumentId(uri); | ||
final String[] split = docId.split(":"); | ||
final String type = split[0]; | ||
|
||
if ("primary".equalsIgnoreCase(type)) { | ||
return Environment.getExternalStorageDirectory() + "/" + split[1]; | ||
} | ||
|
||
// TODO handle non-primary volumes | ||
} | ||
// DownloadsProvider | ||
else if (isDownloadsDocument(uri)) { | ||
|
||
final String id = DocumentsContract.getDocumentId(uri); | ||
final Uri contentUri = ContentUris.withAppendedId( | ||
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); | ||
|
||
return getDataColumn(context, contentUri, null, null); | ||
} | ||
// MediaProvider | ||
else if (isMediaDocument(uri)) { | ||
final String docId = DocumentsContract.getDocumentId(uri); | ||
final String[] split = docId.split(":"); | ||
final String type = split[0]; | ||
|
||
Uri contentUri = null; | ||
if ("image".equals(type)) { | ||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; | ||
} else if ("video".equals(type)) { | ||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; | ||
} else if ("audio".equals(type)) { | ||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; | ||
} | ||
|
||
final String selection = "_id=?"; | ||
final String[] selectionArgs = new String[] { | ||
split[1] | ||
}; | ||
|
||
return getDataColumn(context, contentUri, selection, selectionArgs); | ||
} | ||
} | ||
// MediaStore (and general) | ||
else if ("content".equalsIgnoreCase(uri.getScheme())) { | ||
return getDataColumn(context, uri, null, null); | ||
} | ||
// File | ||
else if ("file".equalsIgnoreCase(uri.getScheme())) { | ||
return uri.getPath(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get the value of the data column for this Uri. This is useful for | ||
* MediaStore Uris, and other file-based ContentProviders. | ||
* | ||
* @param context The context. | ||
* @param uri The Uri to query. | ||
* @param selection (Optional) Filter used in the query. | ||
* @param selectionArgs (Optional) Selection arguments used in the query. | ||
* @return The value of the _data column, which is typically a file path. | ||
*/ | ||
public static String getDataColumn(Context context, Uri uri, String selection, | ||
String[] selectionArgs) { | ||
|
||
Cursor cursor = null; | ||
final String column = "_data"; | ||
final String[] projection = { | ||
column | ||
}; | ||
|
||
try { | ||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, | ||
null); | ||
if (cursor != null && cursor.moveToFirst()) { | ||
final int column_index = cursor.getColumnIndexOrThrow(column); | ||
return cursor.getString(column_index); | ||
} | ||
} finally { | ||
if (cursor != null) | ||
cursor.close(); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
/** | ||
* @param uri The Uri to check. | ||
* @return Whether the Uri authority is ExternalStorageProvider. | ||
*/ | ||
public static boolean isExternalStorageDocument(Uri uri) { | ||
return "com.android.externalstorage.documents".equals(uri.getAuthority()); | ||
} | ||
|
||
/** | ||
* @param uri The Uri to check. | ||
* @return Whether the Uri authority is DownloadsProvider. | ||
*/ | ||
public static boolean isDownloadsDocument(Uri uri) { | ||
return "com.android.providers.downloads.documents".equals(uri.getAuthority()); | ||
} | ||
|
||
/** | ||
* @param uri The Uri to check. | ||
* @return Whether the Uri authority is MediaProvider. | ||
*/ | ||
public static boolean isMediaDocument(Uri uri) { | ||
return "com.android.providers.media.documents".equals(uri.getAuthority()); | ||
} | ||
} |
Oops, something went wrong.