-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
266 additions
and
43 deletions.
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/takisoft/preferencefix/ActivityResultTestPreference.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,49 @@ | ||
package com.takisoft.preferencefix; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.preference.Preference; | ||
import android.util.AttributeSet; | ||
import android.widget.Toast; | ||
|
||
import com.takisoft.fix.support.v7.preference.PreferenceActivityResultListener; | ||
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat; | ||
|
||
public class ActivityResultTestPreference extends Preference implements PreferenceActivityResultListener { | ||
public static final int RC_GET_CONTENT = 3462; | ||
|
||
public ActivityResultTestPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
public ActivityResultTestPreference(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public ActivityResultTestPreference(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public ActivityResultTestPreference(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public void onPreferenceClick(@NonNull PreferenceFragmentCompat fragment, @NonNull Preference preference) { | ||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); | ||
intent.setType("*/*"); | ||
intent.addCategory(Intent.CATEGORY_OPENABLE); | ||
|
||
fragment.startActivityForResult(intent, RC_GET_CONTENT); | ||
} | ||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
if (requestCode == RC_GET_CONTENT && resultCode == Activity.RESULT_OK && data != null) { | ||
Toast.makeText(getContext(), data.getDataString(), Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
37 changes: 37 additions & 0 deletions
37
...rc/main/java/com/takisoft/fix/support/v7/preference/PreferenceActivityResultListener.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,37 @@ | ||
package com.takisoft.fix.support.v7.preference; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v7.preference.Preference; | ||
|
||
/** | ||
* An interface for custom preferences that want to handle click events by either starting an | ||
* {@link Activity} for results calling {@link Fragment#startActivityForResult(Intent, int)} or | ||
* using the supplied {@link PreferenceFragmentCompat} fragment manually (e.g. adding a fragment to | ||
* it). | ||
*/ | ||
public interface PreferenceActivityResultListener { | ||
/** | ||
* Called when the user clicks on the preference. | ||
* | ||
* @param fragment The preference fragment that shows the preference screen. | ||
* @param preference The preference instance. | ||
*/ | ||
void onPreferenceClick(@NonNull PreferenceFragmentCompat fragment, @NonNull Preference preference); | ||
|
||
/** | ||
* Called when an activity you launched exits, giving you the requestCode | ||
* you started it with, the resultCode it returned, and any additional | ||
* data from it. The <var>resultCode</var> will be | ||
* {@link Activity#RESULT_CANCELED} if the activity explicitly returned that, | ||
* didn't return any result, or crashed during its operation. | ||
* | ||
* @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from. | ||
* @param resultCode The integer result code returned by the child activity through its setResult(). | ||
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). | ||
*/ | ||
void onActivityResult(int requestCode, int resultCode, @Nullable Intent data); | ||
} |
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
Oops, something went wrong.