-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from TheCodeMonks/Share-As-Image
Share as image
- Loading branch information
Showing
21 changed files
with
4,033 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
76 changes: 76 additions & 0 deletions
76
app/src/main/java/thecodemonks/org/nottzapp/ui/dialog/ErrorDialog.kt
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,76 @@ | ||
/* | ||
* | ||
* * | ||
* * * MIT License | ||
* * * | ||
* * * Copyright (c) 2020 Spikey Sanju | ||
* * * | ||
* * * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* * * of this software and associated documentation files (the "Software"), to deal | ||
* * * in the Software without restriction, including without limitation the rights | ||
* * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* * * copies of the Software, and to permit persons to whom the Software is | ||
* * * furnished to do so, subject to the following conditions: | ||
* * * | ||
* * * The above copyright notice and this permission notice shall be included in all | ||
* * * copies or substantial portions of the Software. | ||
* * * | ||
* * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* * * SOFTWARE. | ||
* * | ||
* | ||
* | ||
*/ | ||
|
||
package thecodemonks.org.nottzapp.ui.dialog | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.WindowManager | ||
import androidx.navigation.fragment.navArgs | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import thecodemonks.org.nottzapp.databinding.ErrorDialogLayoutBinding | ||
|
||
class ErrorDialog : BottomSheetDialogFragment() { | ||
private var _binding: ErrorDialogLayoutBinding? = null | ||
private val binding get() = _binding!! | ||
private val args: ErrorDialogArgs by navArgs() | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = ErrorDialogLayoutBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
binding.run { | ||
dialogTitle.text = args.title | ||
dialogMessage.text = args.message | ||
dialogButtonOk.setOnClickListener { dialog?.dismiss() } | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
dialog?.window?.setLayout( | ||
WindowManager.LayoutParams.MATCH_PARENT, | ||
WindowManager.LayoutParams.MATCH_PARENT | ||
) | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
_binding = null | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/main/java/thecodemonks/org/nottzapp/utils/SaveBitmap.kt
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,65 @@ | ||
/* | ||
* | ||
* * | ||
* * * MIT License | ||
* * * | ||
* * * Copyright (c) 2020 Spikey Sanju | ||
* * * | ||
* * * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* * * of this software and associated documentation files (the "Software"), to deal | ||
* * * in the Software without restriction, including without limitation the rights | ||
* * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* * * copies of the Software, and to permit persons to whom the Software is | ||
* * * furnished to do so, subject to the following conditions: | ||
* * * | ||
* * * The above copyright notice and this permission notice shall be included in all | ||
* * * copies or substantial portions of the Software. | ||
* * * | ||
* * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* * * SOFTWARE. | ||
* * | ||
* | ||
* | ||
*/ | ||
|
||
package thecodemonks.org.nottzapp.utils | ||
|
||
import android.app.Activity | ||
import android.content.ContentValues | ||
import android.graphics.Bitmap | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.os.Environment | ||
import android.provider.MediaStore | ||
|
||
@JvmField | ||
val DEFAULT_FILENAME = "${"Notzz" + System.currentTimeMillis()}.png" | ||
|
||
fun saveBitmap(activity: Activity, bitmap: Bitmap, filename: String = DEFAULT_FILENAME): Uri? { | ||
val contentValues = ContentValues().apply { | ||
put(MediaStore.MediaColumns.DISPLAY_NAME, filename) | ||
put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg") | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES) | ||
} | ||
} | ||
|
||
val contentResolver = activity.contentResolver | ||
|
||
val imageUri: Uri? = contentResolver.insert( | ||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | ||
contentValues | ||
) | ||
|
||
return imageUri.also { | ||
val fileOutputStream = imageUri?.let { contentResolver.openOutputStream(it) } | ||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream) | ||
fileOutputStream?.close() | ||
} | ||
} |
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
Oops, something went wrong.