hi i m new in android page curl application, i show the pdf file using mupdf opensource via. here using intent action view, so only scroll is working but i need page curl.if any body know the answer please help this concept. thank you.
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mAlertBuilder = new AlertDialog.Builder(this);
if (core == null) {
core = (MuPDFCore)getLastNonConfigurationInstance();
if (savedInstanceState != null && savedInstanceState.containsKey("FileName")) {
mFileName = savedInstanceState.getString("FileName");
}
}
if (core == null) {
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
if (uri.toString().startsWith("content://media/external/file")) {
// Handle view requests from the Transformer Prime's file manager
// Hopefully other file managers will use this same scheme, if not
// using explicit paths.
Cursor cursor = getContentResolver().query(uri, new String[]{"_data"}, null, null, null);
if (cursor.moveToFirst()) {
uri = Uri.parse(cursor.getString(0));
}
}
core = openFile(Uri.decode(uri.getEncodedPath()));
}
if (core != null && core.needsPassword()) {
requestPassword(savedInstanceState);
return;
}
}
if (core == null)
{
AlertDialog alert = mAlertBuilder.create();
alert.setTitle(R.string.open_failed);
alert.setButton(AlertDialog.BUTTON_POSITIVE, "Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.show();
return;
}
createUI(savedInstanceState);
}
Get the code from here android_page_curl and link
From here you can download the source code for page curl effect.
Check this link for checkout source code from Google Code.
Related
I am using zxing in my android application to read QR_CODE and Barcodes. My application is unable to read the CODE_39 using zxing. I am using the following code in CaptureActivity OnResume Method:
Intent intent = getIntent();
String action = intent == null ? null : intent.getAction();
String dataString = intent == null ? null : intent.getDataString();
if (intent != null && action != null) {
if (action.equals(Intents.Scan.ACTION)) {
//Scan the formats the intent requested, and return the
//result
//to the calling activity.
source = Source.NATIVE_APP_INTENT;
decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
} else if (dataString != null
&& dataString.contains(PRODUCT_SEARCH_URL_PREFIX)
&& dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {
// Scan only products and send the result to mobile Product
// Search.
source = Source.PRODUCT_SEARCH_LINK;
sourceUrl = dataString;
decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;
} else if (dataString != null
&& dataString.startsWith(ZXING_URL)) {
// Scan formats requested in query string (all formats if
// none
// specified).
// If a return URL is specified, send the results there.
// Otherwise, handle it ourselves.
source = Source.ZXING_LINK;
sourceUrl = dataString;
Uri inputUri = Uri.parse(sourceUrl);
returnUrlTemplate = inputUri
.getQueryParameter(RETURN_URL_PARAM);
decodeFormats = DecodeFormatManager
.parseDecodeFormats(inputUri);
} else {
// Scan all formats and handle the results ourselves
// (launched
// from Home).
source = Source.NONE;
decodeFormats = null;
}
characterSet = intent
.getStringExtra(Intents.Scan.CHARACTER_SET);
Please Help me to solve this issuse. Thanks in advance.
If you are using Android Studio then Add those dependancies-
compile 'me.dm7.barcodescanner:zxing:1.8.3'
compile 'com.journeyapps:zxing-android-embedded:3.0.2#aar'
compile 'com.google.zxing:core:3.2.0'
Zxing Automatically takes code type while scanning
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES)
Here which is consider all types of codes by default
If you want specific QR then just
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
Use following code-
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class YourActivity extends Activity {
//Barcode Scanning
private ZXingScannerView mScannerView;
// This is your click listener
public void checkBarcode(View v) {
try {
IntentIntegrator integrator = new IntentIntegrator(GateEntryActivity.this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.initiateScan();
//start the scanning activity from the com.google.zxing.client.android.SCAN intent
// Programmatically initialize the scanner view
// setContentView(mScannerView);
} catch (ActivityNotFoundException anfe) {
//on catch, show the download dialog
showDialog(GateEntryActivity.this, "No Scanner Found", "Download a scanner code activity?", "Yes", "No").show();
}
}
//alert dialog for downloadDialog
private static AlertDialog showDialog(final Activity act, CharSequence title, CharSequence message, CharSequence buttonYes, CharSequence buttonNo) {
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(act);
downloadDialog.setTitle(title);
downloadDialog.setMessage(message);
downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
Uri uri = Uri.parse("market://search?q=pname:" + "com.google.zxing.client.android");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
act.startActivity(intent);
} catch (ActivityNotFoundException anfe) {
}
}
});
downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
}
});
return downloadDialog.show();
}
//on ActivityResult method
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
Log.d("MainActivity", "Weird");
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
}
}
Good day!
i am quite new in programming and i am trying to make a simple android app. i have here 2 edittext and 2 buttons inside my activity and what i want them to do is get the number of prefered contacts to text and the 1st edittext and 1st button succeeded but my problem is the button 2 also put the number on the 1st edittext that is supposed to put in 2nd edittext any idea?
this is my code..
public class SA extends Activity {
EditText con1;
EditText con2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_s);
con1 = (EditText) findViewById(R.id.cnum1);
con2 = (EditText) findViewById(R.id.cnum2);
((Button)findViewById(R.id.btnSelectContact1)).setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
// user BoD suggests using Intent.ACTION_PICK instead of .ACTION_GET_CONTENT to avoid the chooser
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
// BoD con't: CONTENT_TYPE instead of CONTENT_ITEM_TYPE
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, 1);
}
});
((Button)findViewById(R.id.btnSelectContact2)).setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v2) {
// user BoD suggests using Intent.ACTION_PICK instead of .ACTION_GET_CONTENT to avoid the chooser
Intent intent2 = new Intent(Intent.ACTION_GET_CONTENT);
// BoD con't: CONTENT_TYPE instead of CONTENT_ITEM_TYPE
intent2.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent2, 1);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
Uri uri = data.getData();
if (uri != null) {
Cursor c = null;
try {
c = getContentResolver().query(uri, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,},
null, null, null);
if (c != null && c.moveToFirst()) {
String number = c.getString(0);
showSelectedNumber(number);
}
} finally {
if (c != null) {
c.close();
}
}
}
}
}
protected void onActivityResult2(int requestCode2, int resultCode2, Intent data2) {
if (data2 != null) {
Uri uri2 = data2.getData();
if (uri2 != null) {
Cursor c2 = null;
try {
c2 = getContentResolver().query(uri2, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,},
null, null, null);
if (c2 != null && c2.moveToNext()) {
String number2 = c2.getString(0);
showSelectedNumber(number2);
}
} finally {
if (c2 != null) {
c2.close();
}
}
}
}
}
public void showSelectedNumber(String number) {
con1.setText(number);
}
public void showSelectedNumber2(String number2) {
con2.setText(number2);
}
No need of onActivityResult2() because startActivityForResult() gives you result back in onActivityResult() method.
So now your question would be, how you can manage different requests? Well, that you can do by passing different request code while calling startActivityForResult().
For example:
startActivityForResult(intent, 1); // first request
startActivityForResult(intent, 2); // second request
// you can pass any random number as a request code
Now you just need to perform the operations according to the request code received back in onActivityResult() method.
For example:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
if(requestCode == 1) {
...
...
} else if (requestCode == 2) {
...
...
}
}
}
I trying to open file or image with on webview on android 4.4.1 & 4.4.2.Since the callback methods are removed for these 2 versions, I added an event to the button type="file" and showed a filechoser. My problem is after choosing the file, I'm not able to atatch it to the button type="file". When I tried by changing the button type="text", it shows the file path name. But I want to use button type="file".
My onActivityResult() code:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intentData) {
super.onActivityResult(requestCode, resultCode, intentData);
if (kitkat()) {
String realPathFromURI = "";
String fullPathUri = null;
if (intentData != null) {
Uri uri = intentData.getData();
if (uri != null) {
Uri uri1 = Uri.parse(uri.toString());
realPathFromURI = Utility.getRealPathFromURI(this, uri1);
if (null != realPathFromURI) {
File file = new File(Utility.getRealPathFromURI(this, uri1));
boolean isMaxSize = Utility.isMaxFileSize(file.length());
if (isMaxSize) {
if (this != null)
Toast.makeText(this.getApplicationContext(), "File Size too large",
Toast.LENGTH_SHORT).show();
return;
}
fullPathUri = file.toString();
} else {
if (this != null) {
Toast.makeText(this.getApplicationContext(), "Invalid File Format", Toast.LENGTH_SHORT).show();
}
}
}
} else {
realPathFromURI = "";
fullPathUri = mCameraPhotoPath;
}
String msgToSend = realPathFromURI;
browser.loadUrl("javascript:KitKatWebviewChooseImgResult(\"" + msgToSend + "\")");
} else {
// code for all versions except of Lollipop
}
}
private boolean kitkat() {
if (android.os.Build.VERSION.RELEASE.startsWith("4.4.1") || android.os.Build.VERSION.RELEASE.startsWith("4.4.2")) {
return true;
} else {
return false;
}
}
and HTML code:
<input name="file" id="files" style="width:195px;font-size:12px;" type="file" data-validation="required" data-validation-error-msg="Please select a file" onclick="showFileChoser()">
script:
function showFileChoser() {
choser.choseImage();
}
function KitKatWebviewChooseImgResult(msg) {
document.getElementById("files").value = msg;
}
When I changed the input type="text", it takes the input and path is shown in the webview. But the same code is not working when input type="text is set".
After choosing the file, How to attach it to button type="file".
Thanks in Advance.
Hi there is a way to select folder where user want to save file in android . I check out http://code.google.com/p/android-file-dialog/
it has functionality to select file but i want to select folder , please provide me usable link or examples.
How about using OI File Manager? This App has the following Intents: PICK_FILE, PICK_DIRECTORY.
There is even sample code on the page for using the Intents.
I used the same source in my app (pretty sure), and there is a block of code:
protected void onListItemClick(ListView l, View v, int position, long id) {
if (file.isDirectory()) {
selectButton.setEnabled(false);
if (file.canRead()) {
lastPositions.put(currentPath, position);
getDir(path.get(position));
} else {
new AlertDialog.Builder(this)
.setIcon(R.drawable.icon)
.setTitle(
"[" + file.getName() + "] "
+ getText(R.string.cant_read_folder))
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
}
}).show();
}
} else {
selectedFile = file;
v.setSelected(true);
selectButton.setEnabled(true);
}
}
You just have to edit how it handle's if (file.isDirectory()). I would recommend declaring a boolean value in your Activity which you change to true if the file is a directory and it is already false. Then if said value is true, then traverse the directory. Also when you change said value to true, you would need to call selectButton.setEnabled(true). This would be quite a bit less complicated than making your own code, I would say.
Check out this answer https://stackoverflow.com/a/28479561/779140
I am mentioned library author so don't hesitate to ask any questions.
I encountered the same issue and I end up using NoNonsense-FilePicker
Add to gradle file
compile 'com.nononsenseapps:filepicker:4.0.0'
Trigger file/folder/dir pick
try {
Utils.makeHepticFeedback(getActivity());
Intent selectDirectoyIntent = new Intent(getActivity(), FilePickerActivity.class);
selectDirectoyIntent.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
selectDirectoyIntent.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
selectDirectoyIntent.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);
selectDirectoyIntent.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
startActivityForResult(selectDirectoyIntent, FILE_CODE);
} catch (Exception e) {
Log.e(LOG_TAG, "exception", e);
e.printStackTrace();
Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_SHORT).show();
}
Handle Activity result to get selected file or files
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == CHOOSE_IMAGE_REQUEST_CODE) {
Uri selectedImageUri = data.getData();
String selectedImagePath = getRealPathFromURI(selectedImageUri);
// NOW WE HAVE OUR WANTED STRING
if (selectedImagePath != null) {
System.out
.println("selectedImagePath is the right one for you!");
PreferenceHelper.getPreferenceHelperInstance().setString(getActivity(),
PreferenceHelper.PLAYER_BACKGROUND,
selectedImageUri.toString());
Glide.with(getActivity()).load(Uri.parse(
PreferenceHelper.getPreferenceHelperInstance().getString(getActivity(),
PreferenceHelper.PLAYER_BACKGROUND
, AppConstants.DEFAULT_BACKGROUND_URL))).
into((ImageView) ButterKnife.findById(getActivity(), R.id.play_back));
}
} else if (requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) {
if (null != data && !data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
// The URI will now be something like content://PACKAGE-NAME/root/path/to/file
Uri uri = data.getData();
// A utility method is provided to transform the URI to a File object
File file = com.nononsenseapps.filepicker.Utils.getFileForUri(uri);
// If you want a URI which matches the old return value, you can do
Uri fileUri = Uri.fromFile(file);
// Do something with the result...
Snackbar.make(fileFormat, "Recording folder updated to" + fileUri.getPath() + " ¯\\_(ツ)_/¯ ", Snackbar.LENGTH_SHORT).show();
AppConfig.RECORDING_FOLDER = fileUri.getPath();
PreferenceHelper.getPreferenceHelperInstance().setString(getActivity(), PreferenceHelper.RECORDING_FOLDER, AppConfig.RECORDING_FOLDER);
setUpSettingValue();
} else {
// Handling multiple results is one extra step
ArrayList<String> paths = data.getStringArrayListExtra(FilePickerActivity.EXTRA_PATHS);
if (paths != null) {
for (String path : paths) {
Uri uri = Uri.parse(path);
// Do something with the URI
File file = com.nononsenseapps.filepicker.Utils.getFileForUri(uri);
// If you want a URI which matches the old return value, you can do
Uri fileUri = Uri.fromFile(file);
// Do something with the result...
Toast.makeText(getActivity(), "Selected dir" + fileUri.getPath(), Toast.LENGTH_SHORT).show();
}
}
}
}
}
Hallo, I writing an app and I want to integrate a sketch-app to draw something and pass the file or path back to my app. At the moment the app can store videos,pictures, sensor data,... and I like to add the ability to store sketches. I found this Code
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.fuelgauge.PowerUsageSummary");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity( intent);
But i dont know how to start sketchbook(app from market). And I need also the path to the saved picture.Or is there an other way? Or Open Source ?
greetings...
So sketchbook is not your application?
To start another program, you need to know the intent filters it uses, or the package name. The developer of sketchbook will be able to supply you with this information (if they wish to share it).
Now when it comes to getting data FROM another app, the only way for that app to return anything to you is if the developer made it that way. It is up to the developer to decide what an Activity returns (if anything). So if you are looking to integrate with a specific application, it would be best for you to contact that developer and discuss how the two apps will interface with each other. On the other hand, if you implemented your own sketch app, you could make it integrate however you'd like.
You'd need to detect that the intent can be handled by the system.
public static boolean canHandleIntent(final Context context, final Intent intent) {
if (intent != null) {
final PackageManager pm = context.getPackageManager();
if (pm != null) {
if (pm.queryIntentActivities(intent, 0).size() > 0) {
return true;
}
}
}
return false;
}
If that returns false you should prompt the user to download the app from the market.
Call,
//Market.getViewPackageOnMarket("org.otherapp.sketchapp");
public class Market {
public static final String Application_BaseMarketUri = "market://details?id=";
public static final Intent getViewPackageOnMarket(final String package_name) {
final Intent result = new Intent(Intent.ACTION_VIEW);
result.setData(Uri.parse(Application_BaseMarketUri + package_name));
return result;
}
}
You'll also need to use startActivityForResult, in your launching activity you need to add these things....
public class MyKillerAppActivity extends Activity {
// Declare constant for the activity result.
public static final int ACTIVITYRESULT_GETSKETCH = 1;
// Call the activity ....
public void someMethod() {
startActivityForResult(intent, ACTIVITYRESULT_GETSKETCH);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
if(requestCode == ACTIVITYRESULT_GETSKETCH) {
handleGetSketchResult(data);
} /* Handle other results if you need to. */
}
}
}
That's kinda a mouthful but there's more! You'll need to interpret the data that comes back from the app. I don't know the format is for the sketch app you're looking into but here's an example on how to get data from the Gallery. The Gallery app returns you a content provider location to load the image that the user picked. This code locates the file path from the content provider and then opens the file and loads it into a Bitmap object for use.
public static Bitmap onActivityResult_getImage(Context context, Intent data) {
Bitmap result = null;
Uri dataUri = data.getData();
final String filePath = findPictureFilePath(context, dataUri);
if(filePath != null) {
result = BitmapFactory.decodeFile(filePath);
}
return result;
}
private static String findPictureFilePath(Context context, Uri dataUri) {
String filePath = null;
final String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(dataUri, projection, null, null, null);
int data_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if(cursor.moveToFirst()) {
filePath = cursor.getString(data_index);
}
} finally {
if(cursor != null) {
cursor.close();
}
}
return filePath;
}